Home | History | Annotate | Line # | Download | only in man3
      1      1.1  christos =pod
      2      1.1  christos 
      3      1.1  christos =head1 NAME
      4      1.1  christos 
      5      1.1  christos PKCS12_newpass - change the password of a PKCS12 structure
      6      1.1  christos 
      7      1.1  christos =head1 SYNOPSIS
      8      1.1  christos 
      9      1.1  christos  #include <openssl/pkcs12.h>
     10      1.1  christos 
     11      1.1  christos  int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
     12      1.1  christos 
     13      1.1  christos =head1 DESCRIPTION
     14      1.1  christos 
     15      1.1  christos PKCS12_newpass() changes the password of a PKCS12 structure.
     16      1.1  christos 
     17      1.1  christos B<p12> is a pointer to a PKCS12 structure. B<oldpass> is the existing password
     18      1.1  christos and B<newpass> is the new password.
     19      1.1  christos 
     20      1.1  christos Each of B<oldpass> and B<newpass> is independently interpreted as a string in
     21      1.1  christos the UTF-8 encoding. If it is not valid UTF-8, it is assumed to be ISO8859-1
     22      1.1  christos instead.
     23      1.1  christos 
     24      1.1  christos In particular, this means that passwords in the locale character set
     25      1.1  christos (or code page on Windows) must potentially be converted to UTF-8 before
     26      1.1  christos use. This may include passwords from local text files, or input from
     27      1.1  christos the terminal or command line. Refer to the documentation of
     28      1.1  christos L<UI_OpenSSL(3)>, for example.
     29      1.1  christos 
     30  1.1.1.3  christos If the PKCS#12 structure does not have a password, then you must use the empty
     31  1.1.1.3  christos string "" for B<oldpass>. Using NULL for B<oldpass> will result in a
     32  1.1.1.3  christos PKCS12_newpass() failure.
     33  1.1.1.3  christos 
     34  1.1.1.3  christos If the wrong password is used for B<oldpass> then the function will fail,
     35  1.1.1.3  christos with a MAC verification error. In rare cases the PKCS12 structure does not
     36  1.1.1.3  christos contain a MAC: in this case it will usually fail with a decryption padding
     37  1.1.1.3  christos error.
     38  1.1.1.3  christos 
     39      1.1  christos =head1 RETURN VALUES
     40      1.1  christos 
     41      1.1  christos PKCS12_newpass() returns 1 on success or 0 on failure. Applications can
     42      1.1  christos retrieve the most recent error from PKCS12_newpass() with ERR_get_error().
     43      1.1  christos 
     44  1.1.1.2  christos =head1 EXAMPLES
     45      1.1  christos 
     46      1.1  christos This example loads a PKCS#12 file, changes its password and writes out
     47      1.1  christos the result to a new file.
     48      1.1  christos 
     49      1.1  christos  #include <stdio.h>
     50      1.1  christos  #include <stdlib.h>
     51      1.1  christos  #include <openssl/pem.h>
     52      1.1  christos  #include <openssl/err.h>
     53      1.1  christos  #include <openssl/pkcs12.h>
     54      1.1  christos 
     55      1.1  christos  int main(int argc, char **argv)
     56      1.1  christos  {
     57      1.1  christos      FILE *fp;
     58      1.1  christos      PKCS12 *p12;
     59      1.1  christos 
     60      1.1  christos      if (argc != 5) {
     61      1.1  christos          fprintf(stderr, "Usage: pkread p12file password newpass opfile\n");
     62      1.1  christos          return 1;
     63      1.1  christos      }
     64      1.1  christos      if ((fp = fopen(argv[1], "rb")) == NULL) {
     65      1.1  christos          fprintf(stderr, "Error opening file %s\n", argv[1]);
     66      1.1  christos          return 1;
     67      1.1  christos      }
     68      1.1  christos      p12 = d2i_PKCS12_fp(fp, NULL);
     69      1.1  christos      fclose(fp);
     70      1.1  christos      if (p12 == NULL) {
     71      1.1  christos          fprintf(stderr, "Error reading PKCS#12 file\n");
     72      1.1  christos          ERR_print_errors_fp(stderr);
     73      1.1  christos          return 1;
     74      1.1  christos      }
     75      1.1  christos      if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) {
     76      1.1  christos          fprintf(stderr, "Error changing password\n");
     77      1.1  christos          ERR_print_errors_fp(stderr);
     78      1.1  christos          PKCS12_free(p12);
     79      1.1  christos          return 1;
     80      1.1  christos      }
     81      1.1  christos      if ((fp = fopen(argv[4], "wb")) == NULL) {
     82      1.1  christos          fprintf(stderr, "Error opening file %s\n", argv[4]);
     83      1.1  christos          PKCS12_free(p12);
     84      1.1  christos          return 1;
     85      1.1  christos      }
     86      1.1  christos      i2d_PKCS12_fp(fp, p12);
     87      1.1  christos      PKCS12_free(p12);
     88      1.1  christos      fclose(fp);
     89      1.1  christos      return 0;
     90      1.1  christos  }
     91      1.1  christos 
     92      1.1  christos 
     93      1.1  christos =head1 BUGS
     94      1.1  christos 
     95      1.1  christos The password format is a NULL terminated ASCII string which is converted to
     96      1.1  christos Unicode form internally. As a result some passwords cannot be supplied to
     97      1.1  christos this function.
     98      1.1  christos 
     99      1.1  christos =head1 SEE ALSO
    100      1.1  christos 
    101      1.1  christos L<PKCS12_create(3)>, L<ERR_get_error(3)>,
    102      1.1  christos L<passphrase-encoding(7)>
    103      1.1  christos 
    104      1.1  christos =head1 COPYRIGHT
    105      1.1  christos 
    106  1.1.1.3  christos Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
    107      1.1  christos 
    108  1.1.1.3  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    109      1.1  christos this file except in compliance with the License.  You can obtain a copy
    110      1.1  christos in the file LICENSE in the source distribution or at
    111      1.1  christos L<https://www.openssl.org/source/license.html>.
    112      1.1  christos 
    113      1.1  christos =cut
    114