113d40330Schristos=pod 213d40330Schristos 313d40330Schristos=head1 NAME 413d40330Schristos 513d40330SchristosPKCS12_newpass - change the password of a PKCS12 structure 613d40330Schristos 713d40330Schristos=head1 SYNOPSIS 813d40330Schristos 913d40330Schristos #include <openssl/pkcs12.h> 1013d40330Schristos 1113d40330Schristos int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass); 1213d40330Schristos 1313d40330Schristos=head1 DESCRIPTION 1413d40330Schristos 1513d40330SchristosPKCS12_newpass() changes the password of a PKCS12 structure. 1613d40330Schristos 1713d40330SchristosB<p12> is a pointer to a PKCS12 structure. B<oldpass> is the existing password 1813d40330Schristosand B<newpass> is the new password. 1913d40330Schristos 2013d40330SchristosEach of B<oldpass> and B<newpass> is independently interpreted as a string in 2113d40330Schristosthe UTF-8 encoding. If it is not valid UTF-8, it is assumed to be ISO8859-1 2213d40330Schristosinstead. 2313d40330Schristos 2413d40330SchristosIn particular, this means that passwords in the locale character set 2513d40330Schristos(or code page on Windows) must potentially be converted to UTF-8 before 2613d40330Schristosuse. This may include passwords from local text files, or input from 2713d40330Schristosthe terminal or command line. Refer to the documentation of 2813d40330SchristosL<UI_OpenSSL(3)>, for example. 2913d40330Schristos 30*b0d17251SchristosIf the PKCS#12 structure does not have a password, then you must use the empty 31*b0d17251Schristosstring "" for B<oldpass>. Using NULL for B<oldpass> will result in a 32*b0d17251SchristosPKCS12_newpass() failure. 33*b0d17251Schristos 34*b0d17251SchristosIf the wrong password is used for B<oldpass> then the function will fail, 35*b0d17251Schristoswith a MAC verification error. In rare cases the PKCS12 structure does not 36*b0d17251Schristoscontain a MAC: in this case it will usually fail with a decryption padding 37*b0d17251Schristoserror. 38*b0d17251Schristos 3913d40330Schristos=head1 RETURN VALUES 4013d40330Schristos 4113d40330SchristosPKCS12_newpass() returns 1 on success or 0 on failure. Applications can 4213d40330Schristosretrieve the most recent error from PKCS12_newpass() with ERR_get_error(). 4313d40330Schristos 444ce06407Schristos=head1 EXAMPLES 4513d40330Schristos 4613d40330SchristosThis example loads a PKCS#12 file, changes its password and writes out 4713d40330Schristosthe result to a new file. 4813d40330Schristos 4913d40330Schristos #include <stdio.h> 5013d40330Schristos #include <stdlib.h> 5113d40330Schristos #include <openssl/pem.h> 5213d40330Schristos #include <openssl/err.h> 5313d40330Schristos #include <openssl/pkcs12.h> 5413d40330Schristos 5513d40330Schristos int main(int argc, char **argv) 5613d40330Schristos { 5713d40330Schristos FILE *fp; 5813d40330Schristos PKCS12 *p12; 5913d40330Schristos 6013d40330Schristos if (argc != 5) { 6113d40330Schristos fprintf(stderr, "Usage: pkread p12file password newpass opfile\n"); 6213d40330Schristos return 1; 6313d40330Schristos } 6413d40330Schristos if ((fp = fopen(argv[1], "rb")) == NULL) { 6513d40330Schristos fprintf(stderr, "Error opening file %s\n", argv[1]); 6613d40330Schristos return 1; 6713d40330Schristos } 6813d40330Schristos p12 = d2i_PKCS12_fp(fp, NULL); 6913d40330Schristos fclose(fp); 7013d40330Schristos if (p12 == NULL) { 7113d40330Schristos fprintf(stderr, "Error reading PKCS#12 file\n"); 7213d40330Schristos ERR_print_errors_fp(stderr); 7313d40330Schristos return 1; 7413d40330Schristos } 7513d40330Schristos if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) { 7613d40330Schristos fprintf(stderr, "Error changing password\n"); 7713d40330Schristos ERR_print_errors_fp(stderr); 7813d40330Schristos PKCS12_free(p12); 7913d40330Schristos return 1; 8013d40330Schristos } 8113d40330Schristos if ((fp = fopen(argv[4], "wb")) == NULL) { 8213d40330Schristos fprintf(stderr, "Error opening file %s\n", argv[4]); 8313d40330Schristos PKCS12_free(p12); 8413d40330Schristos return 1; 8513d40330Schristos } 8613d40330Schristos i2d_PKCS12_fp(fp, p12); 8713d40330Schristos PKCS12_free(p12); 8813d40330Schristos fclose(fp); 8913d40330Schristos return 0; 9013d40330Schristos } 9113d40330Schristos 9213d40330Schristos 9313d40330Schristos=head1 BUGS 9413d40330Schristos 9513d40330SchristosThe password format is a NULL terminated ASCII string which is converted to 9613d40330SchristosUnicode form internally. As a result some passwords cannot be supplied to 9713d40330Schristosthis function. 9813d40330Schristos 9913d40330Schristos=head1 SEE ALSO 10013d40330Schristos 10113d40330SchristosL<PKCS12_create(3)>, L<ERR_get_error(3)>, 10213d40330SchristosL<passphrase-encoding(7)> 10313d40330Schristos 10413d40330Schristos=head1 COPYRIGHT 10513d40330Schristos 106*b0d17251SchristosCopyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. 10713d40330Schristos 108*b0d17251SchristosLicensed under the Apache License 2.0 (the "License"). You may not use 10913d40330Schristosthis file except in compliance with the License. You can obtain a copy 11013d40330Schristosin the file LICENSE in the source distribution or at 11113d40330SchristosL<https://www.openssl.org/source/license.html>. 11213d40330Schristos 11313d40330Schristos=cut 114