Debian Codegraph @

upstream/debian-unstable/man3/PKCS12_newpass.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "PKCS12_NEWPASS 3SSL"
58 .TH PKCS12_NEWPASS 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 PKCS12_newpass \- change the password of a PKCS12 structure
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& #include <openssl/pkcs12.h>
69 \&
70 \& int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
71 .Ve
72 .SH DESCRIPTION
73 .IX Header "DESCRIPTION"
74 \&\fBPKCS12_newpass()\fR changes the password of a PKCS12 structure.
75 .PP
76 \&\fBp12\fR is a pointer to a PKCS12 structure. \fBoldpass\fR is the existing password
77 and \fBnewpass\fR is the new password.
78 .PP
79 Each of \fBoldpass\fR and \fBnewpass\fR is independently interpreted as a string in
80 the UTF\-8 encoding. If it is not valid UTF\-8, it is assumed to be ISO8859\-1
81 instead.
82 .PP
83 In particular, this means that passwords in the locale character set
84 (or code page on Windows) must potentially be converted to UTF\-8 before
85 use. This may include passwords from local text files, or input from
86 the terminal or command line. Refer to the documentation of
87 \&\fBUI_OpenSSL\fR\|(3), for example.
88 .PP
89 If the PKCS#12 structure does not have a password, then you must use the empty
90 string "" for \fBoldpass\fR. Using NULL for \fBoldpass\fR will result in a
91 \&\fBPKCS12_newpass()\fR failure.
92 .PP
93 If the wrong password is used for \fBoldpass\fR then the function will fail,
94 with a MAC verification error. In rare cases the PKCS12 structure does not
95 contain a MAC: in this case it will usually fail with a decryption padding
96 error.
97 .SH "RETURN VALUES"
98 .IX Header "RETURN VALUES"
99 \&\fBPKCS12_newpass()\fR returns 1 on success or 0 on failure. Applications can
100 retrieve the most recent error from \fBPKCS12_newpass()\fR with \fBERR_get_error()\fR.
101 .SH EXAMPLES
102 .IX Header "EXAMPLES"
103 This example loads a PKCS#12 file, changes its password and writes out
104 the result to a new file.
105 .PP
106 .Vb 5
107 \& #include <stdio.h>
108 \& #include <stdlib.h>
109 \& #include <openssl/pem.h>
110 \& #include <openssl/err.h>
111 \& #include <openssl/pkcs12.h>
112 \&
113 \& int main(int argc, char **argv)
114 \& {
115 \& FILE *fp;
116 \& PKCS12 *p12;
117 \&
118 \& if (argc != 5) {
119 \& fprintf(stderr, "Usage: pkread p12file password newpass opfile\en");
120 \& return 1;
121 \& }
122 \& if ((fp = fopen(argv[1], "rb")) == NULL) {
123 \& fprintf(stderr, "Error opening file %s\en", argv[1]);
124 \& return 1;
125 \& }
126 \& p12 = d2i_PKCS12_fp(fp, NULL);
127 \& fclose(fp);
128 \& if (p12 == NULL) {
129 \& fprintf(stderr, "Error reading PKCS#12 file\en");
130 \& ERR_print_errors_fp(stderr);
131 \& return 1;
132 \& }
133 \& if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) {
134 \& fprintf(stderr, "Error changing password\en");
135 \& ERR_print_errors_fp(stderr);
136 \& PKCS12_free(p12);
137 \& return 1;
138 \& }
139 \& if ((fp = fopen(argv[4], "wb")) == NULL) {
140 \& fprintf(stderr, "Error opening file %s\en", argv[4]);
141 \& PKCS12_free(p12);
142 \& return 1;
143 \& }
144 \& i2d_PKCS12_fp(fp, p12);
145 \& PKCS12_free(p12);
146 \& fclose(fp);
147 \& return 0;
148 \& }
149 .Ve
150 .SH BUGS
151 .IX Header "BUGS"
152 The password format is a NULL terminated ASCII string which is converted to
153 Unicode form internally. As a result some passwords cannot be supplied to
154 this function.
155 .SH "SEE ALSO"
156 .IX Header "SEE ALSO"
157 \&\fBPKCS12_create\fR\|(3), \fBERR_get_error\fR\|(3),
158 \&\fBpassphrase\-encoding\fR\|(7)
159 .SH COPYRIGHT
160 .IX Header "COPYRIGHT"
161 Copyright 2016\-2018 The OpenSSL Project Authors. All Rights Reserved.
162 .PP
163 Licensed under the Apache License 2.0 (the "License"). You may not use
164 this file except in compliance with the License. You can obtain a copy
165 in the file LICENSE in the source distribution or at
166 <https://www.openssl.org/source/license.html>.