Blame doc/man3/PKCS12_newpass.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
PKCS12_newpass - change the password of a PKCS12 structure
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/pkcs12.h>
Packit c4476c
Packit c4476c
 int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
PKCS12_newpass() changes the password of a PKCS12 structure.
Packit c4476c
Packit c4476c
B<p12> is a pointer to a PKCS12 structure. B<oldpass> is the existing password
Packit c4476c
and B<newpass> is the new password.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
Each of B<oldpass> and B<newpass> is independently interpreted as a string in
Packit c4476c
the UTF-8 encoding. If it is not valid UTF-8, it is assumed to be ISO8859-1
Packit c4476c
instead.
Packit c4476c
Packit c4476c
In particular, this means that passwords in the locale character set
Packit c4476c
(or code page on Windows) must potentially be converted to UTF-8 before
Packit c4476c
use. This may include passwords from local text files, or input from
Packit c4476c
the terminal or command line. Refer to the documentation of
Packit c4476c
L<UI_OpenSSL(3)>, for example.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
PKCS12_newpass() returns 1 on success or 0 on failure. Applications can
Packit c4476c
retrieve the most recent error from PKCS12_newpass() with ERR_get_error().
Packit c4476c
Packit c4476c
=head1 EXAMPLES
Packit c4476c
Packit c4476c
This example loads a PKCS#12 file, changes its password and writes out
Packit c4476c
the result to a new file.
Packit c4476c
Packit c4476c
 #include <stdio.h>
Packit c4476c
 #include <stdlib.h>
Packit c4476c
 #include <openssl/pem.h>
Packit c4476c
 #include <openssl/err.h>
Packit c4476c
 #include <openssl/pkcs12.h>
Packit c4476c
Packit c4476c
 int main(int argc, char **argv)
Packit c4476c
 {
Packit c4476c
     FILE *fp;
Packit c4476c
     PKCS12 *p12;
Packit c4476c
Packit c4476c
     if (argc != 5) {
Packit c4476c
         fprintf(stderr, "Usage: pkread p12file password newpass opfile\n");
Packit c4476c
         return 1;
Packit c4476c
     }
Packit c4476c
     if ((fp = fopen(argv[1], "rb")) == NULL) {
Packit c4476c
         fprintf(stderr, "Error opening file %s\n", argv[1]);
Packit c4476c
         return 1;
Packit c4476c
     }
Packit c4476c
     p12 = d2i_PKCS12_fp(fp, NULL);
Packit c4476c
     fclose(fp);
Packit c4476c
     if (p12 == NULL) {
Packit c4476c
         fprintf(stderr, "Error reading PKCS#12 file\n");
Packit c4476c
         ERR_print_errors_fp(stderr);
Packit c4476c
         return 1;
Packit c4476c
     }
Packit c4476c
     if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) {
Packit c4476c
         fprintf(stderr, "Error changing password\n");
Packit c4476c
         ERR_print_errors_fp(stderr);
Packit c4476c
         PKCS12_free(p12);
Packit c4476c
         return 1;
Packit c4476c
     }
Packit c4476c
     if ((fp = fopen(argv[4], "wb")) == NULL) {
Packit c4476c
         fprintf(stderr, "Error opening file %s\n", argv[4]);
Packit c4476c
         PKCS12_free(p12);
Packit c4476c
         return 1;
Packit c4476c
     }
Packit c4476c
     i2d_PKCS12_fp(fp, p12);
Packit c4476c
     PKCS12_free(p12);
Packit c4476c
     fclose(fp);
Packit c4476c
     return 0;
Packit c4476c
 }
Packit c4476c
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
If the PKCS#12 structure does not have a password, then you must use the empty
Packit c4476c
string "" for B<oldpass>. Using NULL for B<oldpass> will result in a
Packit c4476c
PKCS12_newpass() failure.
Packit c4476c
Packit c4476c
If the wrong password is used for B<oldpass> then the function will fail,
Packit c4476c
with a MAC verification error. In rare cases the PKCS12 structure does not
Packit c4476c
contain a MAC: in this case it will usually fail with a decryption padding
Packit c4476c
error.
Packit c4476c
Packit c4476c
=head1 BUGS
Packit c4476c
Packit c4476c
The password format is a NULL terminated ASCII string which is converted to
Packit c4476c
Unicode form internally. As a result some passwords cannot be supplied to
Packit c4476c
this function.
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<PKCS12_create(3)>, L<ERR_get_error(3)>,
Packit c4476c
L<passphrase-encoding(7)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut