/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. ASN.1 utility functions header Copyright 2017 Alexander Zakharov This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RDASN_H #define RDASN_H #include #include #include #include "utils.h" #ifdef __cplusplus extern "C" { #endif #define OID_SHA_WITH_RSA_SIGNATURE "1.3.14.3.2.15" #define OID_MD5_WITH_RSA_SIGNATURE "1.3.14.3.2.25" /** * Initialize the ASN.1 library. * * This function initializes the ASN.1 library and should be called before any other ASN.1 functions. * * Returns: 0 on success, or a non-zero error code on failure. */ extern int init_asn1_lib(void); /** * Encode an RSA public key into DER PKCS#1 format. * * This function encodes an RSA public key into DER PKCS#1 format. The modulus and exponent of the public key are * provided as input, and the encoded key is returned in the output buffer. * * Parameters: * - m: A pointer to a gnutls_datum_t structure that contains the modulus of the public key. * - e: A pointer to a gnutls_datum_t structure that contains the exponent of the public key. * - out: A pointer to the output buffer where the encoded key will be stored. * - out_len: A pointer to an integer that will be set to the length of the encoded key. * * Returns: 0 on success, or a non-zero error code on failure. */ extern int write_pkcs1_der_pubkey(const gnutls_datum_t *m, const gnutls_datum_t *e, uint8_t *out, int *out_len); /** * Read the public key algorithm OID from a DER encoded x.509 certificate. * * This function reads the public key algorithm OID from a DER encoded x.509 certificate. The certificate is provided * as input, and the OID is returned in the output buffer. * * Parameters: * - data: A pointer to the input buffer that contains the DER encoded x.509 certificate. * - len: The length of the input buffer. * - oid: A pointer to the output buffer where the OID will be stored. * - oid_size: A pointer to an integer that will be set to the length of the OID. * * Returns: 0 on success, or a non-zero error code on failure. */ extern int libtasn_read_cert_pk_oid(uint8_t *data, size_t len, char *oid, size_t *oid_size); /** * Read the public key parameters from a DER encoded x.509 certificate. * * This function reads the public key parameters (modulus and exponent) from a DER encoded x.509 certificate. The * certificate is provided as input, and the parameters are returned in the output buffers. * * Parameters: * - data: A pointer to the input buffer that contains the DER encoded x.509 certificate. * - len: The length of the input buffer. * - m: A pointer to a gnutls_datum_t structure that will be set to the modulus of the public key. * - e: A pointer to a gnutls_datum_t structure that will be set to the exponent of the public key. * * Returns: 0 on success, or a non-zero error code on failure. */ extern int libtasn_read_cert_pk_parameters(uint8_t *data, size_t len, gnutls_datum_t *m, gnutls_datum_t *e); #ifdef __cplusplus } #endif #endif /* RDASN_H */