CryptoPassphrase  Diff

Differences From Artifact [982ba32868]:

To Artifact [2b9964b6fe]:


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
		{ 'r', @"repeat", 0, &_repeat, NULL },
		{ '\0', nil, 0, NULL, NULL }
	};
	OFOptionsParser *optionsParser =
	    [OFOptionsParser parserWithOptions: options];
	of_unichar_t option;
	char *passphrase;
	OFString *site, *prompt;

	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'h':
			showHelp(of_stdout, true);

			[OFApplication terminate];







|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
		{ 'r', @"repeat", 0, &_repeat, NULL },
		{ '\0', nil, 0, NULL, NULL }
	};
	OFOptionsParser *optionsParser =
	    [OFOptionsParser parserWithOptions: options];
	of_unichar_t option;
	char *passphrase;
	OFString *prompt;

	while ((option = [optionsParser nextOption]) != '\0') {
		switch (option) {
		case 'h':
			showHelp(of_stdout, true);

			[OFApplication terminate];
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

	if ([[optionsParser remainingArguments] count] != 1) {
		showHelp(of_stderr, false);

		[OFApplication terminateWithStatus: 1];
	}

	site = [[optionsParser remainingArguments] firstObject];
	prompt = [OFString stringWithFormat: @"Passphrase for site \"%@\": ",
					     site];

	id <PasswordGenerator> generator = (_legacy
	    ? [LegacyPasswordGenerator generator]
	    : [NewPasswordGenerator generator]);
	generator.site = [[optionsParser remainingArguments] firstObject];

	if (lengthStr != nil) {
		bool invalid = false;







<
<
<
<







103
104
105
106
107
108
109




110
111
112
113
114
115
116

	if ([[optionsParser remainingArguments] count] != 1) {
		showHelp(of_stderr, false);

		[OFApplication terminateWithStatus: 1];
	}





	id <PasswordGenerator> generator = (_legacy
	    ? [LegacyPasswordGenerator generator]
	    : [NewPasswordGenerator generator]);
	generator.site = [[optionsParser remainingArguments] firstObject];

	if (lengthStr != nil) {
		bool invalid = false;
132
133
134
135
136
137
138



139
140
141




























142
143
144
145
146
147
148
			    @"%@: Invalid length: %@\n",
			    [OFApplication programName], lengthStr];

			[OFApplication terminateWithStatus: 1];
		}
	}




	passphrase = getpass(
	    [prompt cStringWithEncoding: [OFSystemInfo native8BitEncoding]]);
	@try {




























		generator.passphrase = passphrase;

		[generator derivePassword];
		@try {
			[of_stdout writeBuffer: generator.output
					length: generator.length];
			[of_stdout writeBuffer: "\n"







>
>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
			    @"%@: Invalid length: %@\n",
			    [OFApplication programName], lengthStr];

			[OFApplication terminateWithStatus: 1];
		}
	}


	prompt = [OFString stringWithFormat: @"Passphrase for site \"%@\": ",
					     generator.site];
	passphrase = getpass(
	    [prompt cStringWithEncoding: [OFSystemInfo native8BitEncoding]]);
	@try {
		if (_repeat) {
			char *passphraseCopy = of_strdup(passphrase);

			if (passphraseCopy == NULL)
				@throw [OFOutOfMemoryException exception];

			@try {
				of_string_encoding_t encoding =
				    [OFSystemInfo native8BitEncoding];

				prompt = [OFString stringWithFormat:
				    @"Repeat passphrase for site \"%@\": ",
				    generator.site];
				passphrase = getpass(
				    [prompt cStringWithEncoding: encoding]);

				if (strcmp(passphrase, passphraseCopy) != 0) {
					[of_stderr writeString:
					    @"Passphrases do not match!\n"];
					[OFApplication terminateWithStatus: 1];
				}
			} @finally {
				of_explicit_memset(passphraseCopy, 0,
				    strlen(passphraseCopy));
				free(passphraseCopy);
			}
		}

		generator.passphrase = passphrase;

		[generator derivePassword];
		@try {
			[of_stdout writeBuffer: generator.output
					length: generator.length];
			[of_stdout writeBuffer: "\n"