• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1995-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  */
9 
10 #include <openssl/asn1.h>
11 #include <openssl/evp.h>
12 #include <openssl/obj.h>
13 #include <openssl/x509.h>
14 
15 #include "internal.h"
16 
17 
X509_REQ_set_version(X509_REQ * x,long version)18 int X509_REQ_set_version(X509_REQ *x, long version) {
19   if (x == NULL) {
20     return 0;
21   }
22   if (version != X509_REQ_VERSION_1) {
23     OPENSSL_PUT_ERROR(X509, X509_R_INVALID_VERSION);
24     return 0;
25   }
26   return ASN1_INTEGER_set_int64(x->req_info->version, version);
27 }
28 
X509_REQ_set_subject_name(X509_REQ * x,X509_NAME * name)29 int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) {
30   if ((x == NULL) || (x->req_info == NULL)) {
31     return 0;
32   }
33   return (X509_NAME_set(&x->req_info->subject, name));
34 }
35 
X509_REQ_set_pubkey(X509_REQ * x,EVP_PKEY * pkey)36 int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) {
37   if ((x == NULL) || (x->req_info == NULL)) {
38     return 0;
39   }
40   return (X509_PUBKEY_set(&x->req_info->pubkey, pkey));
41 }
42 
X509_REQ_set1_signature_algo(X509_REQ * req,const X509_ALGOR * algo)43 int X509_REQ_set1_signature_algo(X509_REQ *req, const X509_ALGOR *algo) {
44   X509_ALGOR *copy = X509_ALGOR_dup(algo);
45   if (copy == NULL) {
46     return 0;
47   }
48 
49   X509_ALGOR_free(req->sig_alg);
50   req->sig_alg = copy;
51   return 1;
52 }
53 
X509_REQ_set1_signature_value(X509_REQ * req,const uint8_t * sig,size_t sig_len)54 int X509_REQ_set1_signature_value(X509_REQ *req, const uint8_t *sig,
55                                   size_t sig_len) {
56   if (!ASN1_STRING_set(req->signature, sig, sig_len)) {
57     return 0;
58   }
59   req->signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
60   req->signature->flags |= ASN1_STRING_FLAG_BITS_LEFT;
61   return 1;
62 }
63