| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/asn1.h> |
| 16 | #include <openssl/evp.h> |
| 17 | #include <openssl/obj.h> |
| 18 | #include <openssl/x509.h> |
| 19 |
| 20 | #include "internal.h" |
| 21 |
| 22 |
| 23 | int X509_REQ_set_version(X509_REQ *x, long version) { |
| 24 | if (x == NULL) { |
| 25 | return 0; |
| 26 | } |
| 27 | if (version != X509_REQ_VERSION_1) { |
| 28 | OPENSSL_PUT_ERROR(X509, X509_R_INVALID_VERSION); |
| 29 | return 0; |
| 30 | } |
| 31 | return ASN1_INTEGER_set_int64(x->req_info->version, version); |
| 32 | } |
| 33 |
| 34 | int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) { |
| 35 | if ((x == NULL) || (x->req_info == NULL)) { |
| 36 | return 0; |
| 37 | } |
| 38 | return (X509_NAME_set(&x->req_info->subject, name)); |
| 39 | } |
| 40 |
| 41 | int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) { |
| 42 | if ((x == NULL) || (x->req_info == NULL)) { |
| 43 | return 0; |
| 44 | } |
| 45 | return (X509_PUBKEY_set(&x->req_info->pubkey, pkey)); |
| 46 | } |
| 47 |
| 48 | int X509_REQ_set1_signature_algo(X509_REQ *req, const X509_ALGOR *algo) { |
| 49 | X509_ALGOR *copy = X509_ALGOR_dup(algo); |
| 50 | if (copy == NULL) { |
| 51 | return 0; |
| 52 | } |
| 53 |
| 54 | X509_ALGOR_free(req->sig_alg); |
| 55 | req->sig_alg = copy; |
| 56 | return 1; |
| 57 | } |
| 58 |
| 59 | int X509_REQ_set1_signature_value(X509_REQ *req, const uint8_t *sig, |
| 60 | size_t sig_len) { |
| 61 | if (!ASN1_STRING_set(req->signature, sig, sig_len)) { |
| 62 | return 0; |
| 63 | } |
| 64 | req->signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); |
| 65 | req->signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; |
| 66 | return 1; |
| 67 | } |
| 68 |