]> git.ipfire.org Git - thirdparty/openssl.git/blame - demos/pkcs12/pkwrite.c
Consolidate copyright for demos
[thirdparty/openssl.git] / demos / pkcs12 / pkwrite.c
CommitLineData
9e200689
RS
1/*
2 * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
84b65340
DSH
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <openssl/pem.h>
13#include <openssl/err.h>
14#include <openssl/pkcs12.h>
15
16/* Simple PKCS#12 file creator */
17
18int main(int argc, char **argv)
19{
0f113f3e
MC
20 FILE *fp;
21 EVP_PKEY *pkey;
22 X509 *cert;
23 PKCS12 *p12;
24 if (argc != 5) {
25 fprintf(stderr, "Usage: pkwrite infile password name p12file\n");
26 exit(1);
27 }
b0700d2c 28 OpenSSL_add_all_algorithms();
0f113f3e 29 ERR_load_crypto_strings();
75ebbd9a 30 if ((fp = fopen(argv[1], "r")) == NULL) {
0f113f3e
MC
31 fprintf(stderr, "Error opening file %s\n", argv[1]);
32 exit(1);
33 }
34 cert = PEM_read_X509(fp, NULL, NULL, NULL);
35 rewind(fp);
36 pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
37 fclose(fp);
38 p12 = PKCS12_create(argv[2], argv[3], pkey, cert, NULL, 0, 0, 0, 0, 0);
39 if (!p12) {
40 fprintf(stderr, "Error creating PKCS#12 structure\n");
41 ERR_print_errors_fp(stderr);
42 exit(1);
43 }
75ebbd9a 44 if ((fp = fopen(argv[4], "wb")) == NULL) {
0f113f3e
MC
45 fprintf(stderr, "Error opening file %s\n", argv[1]);
46 ERR_print_errors_fp(stderr);
47 exit(1);
48 }
49 i2d_PKCS12_fp(fp, p12);
50 PKCS12_free(p12);
51 fclose(fp);
52 return 0;
84b65340 53}