xref: /openbsd/lib/libcrypto/man/PKCS12_newpass.3 (revision 274d7c50)
1.\"	$OpenBSD: PKCS12_newpass.3,v 1.4 2019/06/14 13:59:32 schwarze Exp $
2.\"	OpenSSL c95a8b4e May 5 14:26:26 2016 +0100
3.\"
4.\" This file was written by Jeffrey Walton <noloader@gmail.com>.
5.\" Copyright (c) 2016 The OpenSSL Project.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in
16.\"    the documentation and/or other materials provided with the
17.\"    distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\"    software must display the following acknowledgment:
21.\"    "This product includes software developed by the OpenSSL Project
22.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\"    endorse or promote products derived from this software without
26.\"    prior written permission. For written permission, please contact
27.\"    openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\"    nor may "OpenSSL" appear in their names without prior written
31.\"    permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\"    acknowledgment:
35.\"    "This product includes software developed by the OpenSSL Project
36.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 14 2019 $
52.Dt PKCS12_NEWPASS 3
53.Os
54.Sh NAME
55.Nm PKCS12_newpass
56.Nd change the password of a PKCS#12 structure
57.Sh SYNOPSIS
58.In openssl/pkcs12.h
59.Ft int
60.Fo PKCS12_newpass
61.Fa "PKCS12 *p12"
62.Fa "const char *oldpass"
63.Fa "const char *newpass"
64.Fc
65.Sh DESCRIPTION
66.Fn PKCS12_newpass
67changes the password of a PKCS#12 structure.
68.Pp
69.Fa p12
70is a pointer to a PKCS#12 structure.
71.Fa oldpass
72is the existing password and
73.Fa newpass
74is the new password.
75.Pp
76If the PKCS#12 structure does not have a password, use the empty
77string
78.Qq \&
79for
80.Fa oldpass .
81Passing
82.Dv NULL
83for
84.Fa oldpass
85results in a
86.Fn PKCS12_newpass
87failure.
88.Pp
89If the wrong password is used for
90.Fa oldpass ,
91the function will fail with a MAC verification error.
92In rare cases, the PKCS#12 structure does not contain a MAC:
93in this case it will usually fail with a decryption padding error.
94.Sh RETURN VALUES
95Upon successful completion, 1 is returned;
96otherwise 0 is returned and an error code can be retrieved with
97.Xr ERR_get_error 3 .
98.Sh EXAMPLES
99This example loads a PKCS#12 file, changes its password,
100and writes out the result to a new file.
101.Bd -literal
102#include <stdio.h>
103#include <stdlib.h>
104#include <openssl/pem.h>
105#include <openssl/err.h>
106#include <openssl/pkcs12.h>
107
108int main(int argc, char **argv)
109{
110	FILE *fp;
111	PKCS12 *p12;
112	if (argc != 5) {
113		fprintf(stderr,
114		    "Usage: pkread p12file password newpass opfile\en");
115		return 1;
116	}
117	if ((fp = fopen(argv[1], "rb")) == NULL) {
118		fprintf(stderr, "Error opening file %s\en", argv[1]);
119		return 1;
120	}
121	p12 = d2i_PKCS12_fp(fp, NULL);
122	fclose(fp);
123	if (p12 == NULL) {
124		fprintf(stderr, "Error reading PKCS#12 file\en");
125		ERR_print_errors_fp(stderr);
126		return 1;
127	}
128	if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) {
129		fprintf(stderr, "Error changing password\en");
130		ERR_print_errors_fp(stderr);
131		PKCS12_free(p12);
132		return 1;
133	}
134	if ((fp = fopen(argv[4], "wb")) == NULL) {
135		fprintf(stderr, "Error opening file %s\en", argv[4]);
136		PKCS12_free(p12);
137		return 1;
138	}
139	i2d_PKCS12_fp(fp, p12);
140	PKCS12_free(p12);
141	fclose(fp);
142	return 0;
143}
144.Ed
145.Sh SEE ALSO
146.Xr PKCS12_create 3 ,
147.Xr PKCS12_new 3
148.Sh HISTORY
149.Fn PKCS12_newpass
150first appeared in OpenSSL 0.9.5 and has been available since
151.Ox 2.7 .
152.Sh BUGS
153The password format is a NUL terminated ASCII string which is
154converted to Unicode form internally.
155As a result, some passwords cannot be supplied to this function.
156