Last active
November 29, 2020 10:12
-
-
Save trueroad/77165de4a367da4eaae7038658262063 to your computer and use it in GitHub Desktop.
tr_libtasn1: C++ class library for libtasn1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BIN = sample | |
OBJS = sample.o tr_libtasn1.o ts_asn1_tab.o | |
ASN1PARSER = asn1Parser | |
all: $(BIN) ts_asn1_tab.c | |
.PHONY: all clean | |
CXXFLAGS += -std=c++11 | |
LDLIBS += -ltasn1 | |
DEPS = $(OBJS:.o=.d) | |
CPPFLAGS += -MMD -MP -MF $(@:.o=.d) -MT $@ | |
-include $(DEPS) | |
$(BIN): $(OBJS) | |
$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@ | |
%_asn1_tab.c: %.asn1 | |
$(ASN1PARSER) -o $@ $^ | |
clean: | |
$(RM) *~ $(OBJS) $(DEPS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// tr_libtasn1: C++ class library for libtasn1 | |
// https://gist.github.com/trueroad/77165de4a367da4eaae7038658262063 | |
// | |
// sample.cc: | |
// Sample for tr_libtasn1 | |
// | |
// Copyright (C) 2019 Masamichi Hosoda. | |
// All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions | |
// are met: | |
// | |
// * Redistributions of source code must retain the above copyright notice, | |
// this list of conditions and the following disclaimer. | |
// | |
// * Redistributions in binary form must reproduce the above copyright notice, | |
// this list of conditions and the following disclaimer in the documentation | |
// and/or other materials provided with the distribution. | |
// | |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
// ARE DISCLAIMED. | |
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
// SUCH DAMAGE. | |
// | |
#include <fstream> | |
#include <iomanip> | |
#include <iostream> | |
#include <stdexcept> | |
#include <string> | |
#include <vector> | |
#include "tr_libtasn1.hh" | |
extern "C" const asn1_static_node ts_asn1_tab[]; | |
void show_hex (const std::vector<unsigned char> &buff) | |
{ | |
std::cout << std::hex; | |
for (int i = 0; i < buff.size (); ++i) | |
{ | |
if ((i % 16) == 0 && i) | |
std::cout << std::endl; | |
std::cout << std::setw (2) << std::setfill ('0') | |
<< static_cast<unsigned int> (buff[i]) << " "; | |
} | |
std::cout << std::dec << std::endl; | |
} | |
int main () | |
{ | |
std::cout | |
<< "Sample for tr_libtasn1: C++ class library for libtasn1" | |
<< std::endl | |
<< "Copyright (C) 2019 Masamichi Hosoda" | |
<< std::endl; | |
try | |
{ | |
std::cout << std::endl << "--- der_coding sample ---" << std::endl; | |
tr_libtasn1::asn1_definition d (ts_asn1_tab); | |
auto s {d.create_element ("PKIXTSP.TimeStampReq")}; | |
s.write_value ("messageImprint.hashAlgorithm.algorithm", | |
"2.16.840.1.101.3.4.2.1"); // SHA-256 | |
std::vector<unsigned char> md (32, 0); // 32 byte zero (dummy SHA-256) | |
s.write_value ("messageImprint.hashedMessage", md); | |
s.write_value ("nonce", "81985529216486895"); // 0x0123456789ABCDEF | |
s.write_value ("version", "1"); | |
s.write_value ("certReq", "TRUE"); | |
s.write_value ("messageImprint.hashAlgorithm.parameters", nullptr); | |
s.write_value ("reqPolicy", nullptr); | |
s.write_value ("extensions", nullptr); | |
auto der {s.der_coding ("")}; | |
std::cout << "der_coding succeeded" << std::endl; | |
show_hex (der); | |
std::ofstream ofs ("der.bin", std::ios::binary); | |
ofs.write (reinterpret_cast<char*> (der.data ()), der.size ()); | |
ofs.close (); | |
std::cout << "der is saved to `der.bin`" << std::endl; | |
{ | |
std::cout << std::endl << "--- der_decoding sample ---" << std::endl; | |
auto s2 {d.create_element ("PKIXTSP.TimeStampReq")}; | |
s2.der_decoding (der); | |
std::cout << "der_decoding succeeded" << std::endl; | |
auto nonce {s2.read_value_binary ("nonce")}; | |
std::cout << "nonce "; | |
show_hex (nonce); | |
} | |
} | |
catch (std::runtime_error &e) | |
{ | |
std::cout << e.what () << std::endl; | |
return 1; | |
} | |
std::cout << std::endl << "complete" << std::endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// tr_libtasn1: C++ class library for libtasn1 | |
// https://gist.github.com/trueroad/77165de4a367da4eaae7038658262063 | |
// | |
// tr_libtasn1.cc: | |
// Implementation for tr_libtasn1 | |
// | |
// Copyright (C) 2019, 2020 Masamichi Hosoda. | |
// All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions | |
// are met: | |
// | |
// * Redistributions of source code must retain the above copyright notice, | |
// this list of conditions and the following disclaimer. | |
// | |
// * Redistributions in binary form must reproduce the above copyright notice, | |
// this list of conditions and the following disclaimer in the documentation | |
// and/or other materials provided with the distribution. | |
// | |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
// ARE DISCLAIMED. | |
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
// SUCH DAMAGE. | |
// | |
#include "tr_libtasn1.hh" | |
#include <iostream> | |
#include <memory> | |
#include <sstream> | |
#include <string> | |
#include <stdexcept> | |
#include <libtasn1.h> | |
namespace tr_libtasn1 | |
{ | |
asn1_definition::asn1_definition (const asn1_static_node * array) | |
{ | |
asn1_node definitions = nullptr; | |
char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; | |
int asn1_result = asn1_array2tree (array, &definitions, errorDescription); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_array2tree error: " | |
<< asn1_strerror (asn1_result) | |
<< ", description: " << errorDescription; | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
definitions_.reset (definitions, | |
[] (asn1_node d) | |
{ | |
asn1_delete_structure (&d); | |
}); | |
} | |
asn1_definition::~asn1_definition () = default; | |
asn1_definition::asn1_definition (const asn1_definition &) = default; | |
asn1_definition& asn1_definition::operator= (const asn1_definition &) = | |
default; | |
asn1_definition::asn1_definition (asn1_definition &&) = default; | |
asn1_definition& asn1_definition::operator= (asn1_definition &&) = | |
default; | |
asn1_structure asn1_definition::create_element (const std::string &name) | |
{ | |
return asn1_structure (*this, name); | |
} | |
asn1_definition::operator asn1_node () const | |
{ | |
return definitions_.get (); | |
} | |
asn1_structure::asn1_structure (const asn1_definition &definition, | |
const std::string &name): | |
definition_ (definition) | |
{ | |
int asn1_result = asn1_create_element (definition_, | |
name.c_str (), | |
&structure_); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_create_element \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
asn1_structure::~asn1_structure () | |
{ | |
asn1_delete_structure (&structure_); | |
} | |
asn1_structure::asn1_structure (asn1_structure &&) = default; | |
asn1_structure& asn1_structure::operator= (asn1_structure &&) = default; | |
void asn1_structure::delete_element (const std::string &name) | |
{ | |
int asn1_result = asn1_delete_element (structure_, | |
name.c_str ()); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_delete_element \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
int asn1_structure::number_of_elements (const std::string &name) | |
{ | |
int num {0}; | |
int asn1_result = asn1_number_of_elements (structure_, | |
name.c_str (), | |
&num); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_number_of_elements \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
return num; | |
} | |
int asn1_structure::number_of_elements_optional (const std::string &name) | |
{ | |
int num {0}; | |
int asn1_result = asn1_number_of_elements (structure_, | |
name.c_str (), | |
&num); | |
if (asn1_result == ASN1_ELEMENT_NOT_FOUND) | |
return 0; | |
else if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_number_of_elements \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
return num; | |
} | |
void asn1_structure::copy_node (const std::string &dst_name, | |
const std::string &src_name) | |
{ | |
int asn1_result = asn1_copy_node (structure_, | |
dst_name.c_str (), | |
structure_, | |
src_name.c_str ()); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_copy_node dst \"" | |
<< dst_name << "\", src \"" << src_name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
void asn1_structure::copy_node (const std::string &dst_name, | |
const asn1_structure &src_structure, | |
const std::string &src_name) | |
{ | |
int asn1_result = asn1_copy_node (structure_, | |
dst_name.c_str (), | |
src_structure, | |
src_name.c_str ()); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_copy_node dst \"" | |
<< dst_name << "\", src \"" << src_name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
void asn1_structure::copy_node_optional (const std::string &dst_name, | |
const std::string &src_name) | |
{ | |
int asn1_result = asn1_copy_node (structure_, | |
dst_name.c_str (), | |
structure_, | |
src_name.c_str ()); | |
if (asn1_result == ASN1_ELEMENT_NOT_FOUND) | |
{ | |
asn1_result = asn1_delete_element (structure_, dst_name.c_str ()); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_delete_element dst \"" | |
<< dst_name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
else if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_copy_node dst \"" | |
<< dst_name << "\", src \"" << src_name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
void asn1_structure::write_value (const std::string &name, | |
const char *value, | |
int len) | |
{ | |
int asn1_result = asn1_write_value (structure_, | |
name.c_str (), | |
value, | |
len); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_write_value char* \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
void asn1_structure::write_value (const std::string &name, | |
const std::vector<unsigned char> &value) | |
{ | |
int asn1_result = asn1_write_value (structure_, | |
name.c_str (), | |
value.data (), | |
value.size ()); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_write_value binary \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
std::vector<unsigned char> | |
asn1_structure::read_value_binary (const std::string &name) | |
{ | |
std::vector<unsigned char> retval; | |
int len {0}; | |
int asn1_result = asn1_read_value (structure_, | |
name.c_str (), | |
nullptr, | |
&len); | |
if (asn1_result == ASN1_MEM_ERROR) | |
{ | |
retval.resize (len); | |
asn1_result = asn1_read_value (structure_, | |
name.c_str (), | |
retval.data (), | |
&len); | |
} | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_read_value binary \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
return retval; | |
} | |
std::string | |
asn1_structure::read_value_string (const std::string &name) | |
{ | |
std::string retval; | |
int len {0}; | |
int asn1_result = asn1_read_value (structure_, | |
name.c_str (), | |
nullptr, | |
&len); | |
if (asn1_result == ASN1_MEM_ERROR) | |
{ | |
retval.resize (len); | |
asn1_result = asn1_read_value (structure_, | |
name.c_str (), | |
&retval[0], | |
&len); | |
} | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_read_value string \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result); | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
if (retval.back () == 0) | |
retval.pop_back (); // remove zero termination | |
return retval; | |
} | |
int asn1_structure::read_value_int (const std::string &name) | |
{ | |
auto buff {read_value_binary (name)}; | |
if (buff.size () > sizeof (int)) | |
{ | |
throw std::runtime_error ("tr_libtasn1: " | |
"asn1_structure::read_value_int: " | |
"size overflow"); | |
} | |
int retval {*(reinterpret_cast<const char*> (&buff[0]))}; | |
for (int i = 1; i < buff.size (); ++i) | |
{ | |
retval = (retval << 8) | buff[i]; | |
} | |
return retval; | |
} | |
std::vector<unsigned char> | |
asn1_structure::der_coding (const std::string &name) | |
{ | |
std::vector<unsigned char> retval; | |
int der_len {0}; | |
char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; | |
int asn1_result = asn1_der_coding (structure_, | |
name.c_str (), | |
nullptr, | |
&der_len, | |
errorDescription); | |
if (asn1_result == ASN1_MEM_ERROR) | |
{ | |
retval.resize (der_len); | |
asn1_result = asn1_der_coding (structure_, | |
name.c_str (), | |
retval.data (), | |
&der_len, | |
errorDescription); | |
} | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_der_coding \"" | |
<< name << "\" error: " | |
<< asn1_strerror (asn1_result) | |
<< ", description: " << errorDescription; | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
return retval; | |
} | |
void asn1_structure::der_decoding (const std::vector<unsigned char> &buffer) | |
{ | |
char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; | |
int asn1_result = asn1_der_decoding (&structure_, | |
buffer.data (), | |
buffer.size (), | |
errorDescription); | |
if (asn1_result != ASN1_SUCCESS) | |
{ | |
std::stringstream ss; | |
ss << "tr_libtasn1: asn1_der_decoding error: " | |
<< asn1_strerror (asn1_result) | |
<< ", description: " << errorDescription; | |
throw std::runtime_error (ss.str ().c_str ()); | |
} | |
} | |
asn1_structure::operator asn1_node () const | |
{ | |
return structure_; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// tr_libtasn1: C++ class library for libtasn1 | |
// https://gist.github.com/trueroad/77165de4a367da4eaae7038658262063 | |
// | |
// tr_libtasn1.hh: | |
// Header file for tr_libtasn1 | |
// | |
// Copyright (C) 2019, 2020 Masamichi Hosoda. | |
// All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions | |
// are met: | |
// | |
// * Redistributions of source code must retain the above copyright notice, | |
// this list of conditions and the following disclaimer. | |
// | |
// * Redistributions in binary form must reproduce the above copyright notice, | |
// this list of conditions and the following disclaimer in the documentation | |
// and/or other materials provided with the distribution. | |
// | |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
// ARE DISCLAIMED. | |
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
// SUCH DAMAGE. | |
// | |
#ifndef INCLUDE_GUARD_TR_LIBTASN1_HH | |
#define INCLUDE_GUARD_TR_LIBTASN1_HH | |
#include <memory> | |
#include <vector> | |
struct asn1_node_st; | |
typedef asn1_node_st *asn1_node; | |
struct asn1_static_node_st; | |
typedef struct asn1_static_node_st asn1_static_node; | |
namespace tr_libtasn1 | |
{ | |
class asn1_structure; | |
class asn1_definition | |
{ | |
public: | |
asn1_definition (const asn1_static_node * /* array */); | |
~asn1_definition (); | |
asn1_definition (const asn1_definition &); | |
asn1_definition& operator= (const asn1_definition &); | |
asn1_definition (asn1_definition &&); | |
asn1_definition& operator= (asn1_definition &&); | |
asn1_structure create_element (const std::string & /* name */); | |
operator asn1_node () const; | |
private: | |
std::shared_ptr<asn1_node_st> definitions_; | |
}; | |
class asn1_structure | |
{ | |
public: | |
asn1_structure (const asn1_definition & /* definition */, | |
const std::string & /* name */); | |
~asn1_structure (); | |
asn1_structure (const asn1_structure &) = delete; | |
asn1_structure& operator= (const asn1_structure &) = delete; | |
asn1_structure (asn1_structure &&); | |
asn1_structure& operator= (asn1_structure &&); | |
void delete_element (const std::string & /* name */); | |
int number_of_elements (const std::string & /* name */); | |
int number_of_elements_optional (const std::string & /* name */); | |
void copy_node (const std::string & /* dst_name */, | |
const std::string & /* src_name */); | |
void copy_node (const std::string & /* dst_name */, | |
const asn1_structure & /* src_structure */, | |
const std::string & /* src_name */); | |
void copy_node_optional (const std::string & /* dst_name */, | |
const std::string & /* src_name */); | |
void write_value (const std::string & /* name */, | |
const char * /* value */, | |
int len = 0); | |
void write_value (const std::string & /* name */, | |
const std::vector<unsigned char> & /* value */); | |
std::vector<unsigned char> | |
read_value_binary (const std::string & /* name */); | |
std::string | |
read_value_string (const std::string & /* name */); | |
int read_value_int (const std::string & /* name */); | |
std::vector<unsigned char> der_coding (const std::string & /* name */); | |
void der_decoding (const std::vector<unsigned char> & /* buffer */); | |
operator asn1_node () const; | |
private: | |
asn1_definition definition_; | |
asn1_node structure_ = nullptr; | |
}; | |
} | |
#endif // INCLUDE_GUARD_TR_LIBTASN1_HH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- From RFC 3161 -- | |
PKIXTSP {iso(1) identified-organization(3) dod(6) internet(1) | |
security(5) mechanisms(5) pkix(7) id-mod(0) id-mod-tsp(13)} | |
DEFINITIONS IMPLICIT TAGS ::= | |
BEGIN | |
-- 2.4.1 | |
TimeStampReq ::= SEQUENCE { | |
version INTEGER { v1(1) }, | |
messageImprint MessageImprint, | |
--a hash algorithm OID and the hash value of the data to be | |
--time-stamped | |
reqPolicy TSAPolicyId OPTIONAL, | |
nonce INTEGER OPTIONAL, | |
certReq BOOLEAN DEFAULT FALSE, | |
extensions [0] IMPLICIT Extensions OPTIONAL } | |
MessageImprint ::= SEQUENCE { | |
hashAlgorithm AlgorithmIdentifier, | |
hashedMessage OCTET STRING } | |
TSAPolicyId ::= OBJECT IDENTIFIER | |
-- 2.4.2 | |
TimeStampResp ::= SEQUENCE { | |
status PKIStatusInfo, | |
timeStampToken TimeStampToken OPTIONAL } | |
-- The status is based on the definition of status | |
-- in section 3.2.3 of [RFC2510] | |
PKIStatusInfo ::= SEQUENCE { | |
status PKIStatus, | |
statusString PKIFreeText OPTIONAL, | |
failInfo PKIFailureInfo OPTIONAL } | |
PKIStatus ::= INTEGER { | |
granted (0), | |
-- when the PKIStatus contains the value zero a TimeStampToken, as | |
-- requested, is present. | |
grantedWithMods (1), | |
-- when the PKIStatus contains the value one a TimeStampToken, | |
-- with modifications, is present. | |
rejection (2), | |
waiting (3), | |
revocationWarning (4), | |
-- this message contains a warning that a revocation is | |
-- imminent | |
revocationNotification (5) | |
-- notification that a revocation has occurred | |
} | |
-- When the TimeStampToken is not present | |
-- failInfo indicates the reason why the | |
-- time-stamp request was rejected and | |
-- may be one of the following values. | |
PKIFailureInfo ::= BIT STRING { | |
badAlg (0), | |
-- unrecognized or unsupported Algorithm Identifier | |
badRequest (2), | |
-- transaction not permitted or supported | |
badDataFormat (5), | |
-- the data submitted has the wrong format | |
timeNotAvailable (14), | |
-- the TSA's time source is not available | |
unacceptedPolicy (15), | |
-- the requested TSA policy is not supported by the TSA. | |
unacceptedExtension (16), | |
-- the requested extension is not supported by the TSA. | |
addInfoNotAvailable (17), | |
-- the additional information requested could not be understood | |
-- or is not available | |
systemFailure (25) | |
-- the request cannot be handled due to system failure | |
} | |
TimeStampToken ::= ContentInfo | |
-- contentType is id-signedData as defined in [CMS] | |
-- content is SignedData as defined in([CMS]) | |
-- eContentType within SignedData is id-ct-TSTInfo | |
-- eContent within SignedData is TSTInfo | |
TSTInfo ::= SEQUENCE { | |
version INTEGER { v1(1) }, | |
policy TSAPolicyId, | |
messageImprint MessageImprint, | |
-- MUST have the same value as the similar field in | |
-- TimeStampReq | |
serialNumber INTEGER, | |
-- Time-Stamping users MUST be ready to accommodate integers | |
-- up to 160 bits. | |
genTime GeneralizedTime, | |
accuracy Accuracy OPTIONAL, | |
ordering BOOLEAN DEFAULT FALSE, | |
nonce INTEGER OPTIONAL, | |
-- MUST be present if the similar field was present | |
-- in TimeStampReq. In that case it MUST have the same value. | |
tsa [0] GeneralName OPTIONAL, | |
extensions [1] IMPLICIT Extensions OPTIONAL } | |
Accuracy ::= SEQUENCE { | |
seconds INTEGER OPTIONAL, | |
millis [0] INTEGER (1..999) OPTIONAL, | |
micros [1] INTEGER (1..999) OPTIONAL } | |
-- ... -- | |
-- From RFC 2459 / 3280 / 5280 -- | |
-- ... -- | |
Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension | |
Extension ::= SEQUENCE { | |
extnID OBJECT IDENTIFIER, | |
critical BOOLEAN DEFAULT FALSE, | |
extnValue OCTET STRING | |
-- contains the DER encoding of an ASN.1 value | |
-- corresponding to the extension type identified | |
-- by extnID | |
} | |
-- ... -- | |
AlgorithmIdentifier ::= SEQUENCE { | |
algorithm OBJECT IDENTIFIER, | |
parameters ANY DEFINED BY algorithm OPTIONAL } | |
-- contains a value of the type | |
-- registered for use with the | |
-- algorithm object identifier value | |
-- ... -- | |
-- From RFC 2510 / 4210 -- | |
-- ... -- | |
PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String | |
-- text encoded as UTF-8 String [RFC3629] (note: each | |
-- UTF8String MAY include an [RFC3066] language tag | |
-- to indicate the language of the contained text | |
-- see [RFC2482] for details) | |
-- ... -- | |
-- From RFC 2630 / 3369 / 3852 / 5652 -- | |
-- ... -- | |
-- Cryptographic Message Syntax | |
ContentInfo ::= SEQUENCE { | |
contentType ContentType, | |
content [0] EXPLICIT ANY DEFINED BY contentType } | |
ContentType ::= OBJECT IDENTIFIER | |
-- ... -- | |
-- From RFC 5280 -- | |
-- ... -- | |
GeneralName ::= CHOICE { | |
otherName [0] AnotherName, | |
rfc822Name [1] IA5String, | |
dNSName [2] IA5String, | |
x400Address [3] ORAddress, | |
directoryName [4] Name, | |
ediPartyName [5] EDIPartyName, | |
uniformResourceIdentifier [6] IA5String, | |
iPAddress [7] OCTET STRING, | |
registeredID [8] OBJECT IDENTIFIER } | |
-- ... -- | |
-- dummy -- | |
-- RFC 5280 | |
AnotherName ::= SEQUENCE OF ANY | |
ORAddress ::= SEQUENCE OF ANY | |
Name ::= SEQUENCE OF ANY | |
EDIPartyName ::= SEQUENCE OF ANY | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if HAVE_CONFIG_H | |
# include "config.h" | |
#endif | |
#include <libtasn1.h> | |
const asn1_static_node ts_asn1_tab[] = { | |
{ "PKIXTSP", 536875024, NULL }, | |
{ NULL, 1610612748, NULL }, | |
{ "iso", 1073741825, "1"}, | |
{ "identified-organization", 1073741825, "3"}, | |
{ "dod", 1073741825, "6"}, | |
{ "internet", 1073741825, "1"}, | |
{ "security", 1073741825, "5"}, | |
{ "mechanisms", 1073741825, "5"}, | |
{ "pkix", 1073741825, "7"}, | |
{ "id-mod", 1073741825, "0"}, | |
{ "id-mod-tsp", 1, "13"}, | |
{ "TimeStampReq", 1610612741, NULL }, | |
{ "version", 1610874883, NULL }, | |
{ "v1", 1, "1"}, | |
{ "messageImprint", 1073741826, "MessageImprint"}, | |
{ "reqPolicy", 1073758210, "TSAPolicyId"}, | |
{ "nonce", 1073758211, NULL }, | |
{ "certReq", 1610645508, NULL }, | |
{ NULL, 131081, NULL }, | |
{ "extensions", 536895490, "Extensions"}, | |
{ NULL, 4104, "0"}, | |
{ "MessageImprint", 1610612741, NULL }, | |
{ "hashAlgorithm", 1073741826, "AlgorithmIdentifier"}, | |
{ "hashedMessage", 7, NULL }, | |
{ "TSAPolicyId", 1073741836, NULL }, | |
{ "TimeStampResp", 1610612741, NULL }, | |
{ "status", 1073741826, "PKIStatusInfo"}, | |
{ "timeStampToken", 16386, "TimeStampToken"}, | |
{ "PKIStatusInfo", 1610612741, NULL }, | |
{ "status", 1073741826, "PKIStatus"}, | |
{ "statusString", 1073758210, "PKIFreeText"}, | |
{ "failInfo", 16386, "PKIFailureInfo"}, | |
{ "PKIStatus", 1610874883, NULL }, | |
{ "granted", 1073741825, "0"}, | |
{ "grantedWithMods", 1073741825, "1"}, | |
{ "rejection", 1073741825, "2"}, | |
{ "waiting", 1073741825, "3"}, | |
{ "revocationWarning", 1073741825, "4"}, | |
{ "revocationNotification", 1, "5"}, | |
{ "PKIFailureInfo", 1610874886, NULL }, | |
{ "badAlg", 1073741825, "0"}, | |
{ "badRequest", 1073741825, "2"}, | |
{ "badDataFormat", 1073741825, "5"}, | |
{ "timeNotAvailable", 1073741825, "14"}, | |
{ "unacceptedPolicy", 1073741825, "15"}, | |
{ "unacceptedExtension", 1073741825, "16"}, | |
{ "addInfoNotAvailable", 1073741825, "17"}, | |
{ "systemFailure", 1, "25"}, | |
{ "TimeStampToken", 1073741826, "ContentInfo"}, | |
{ "TSTInfo", 1610612741, NULL }, | |
{ "version", 1610874883, NULL }, | |
{ "v1", 1, "1"}, | |
{ "policy", 1073741826, "TSAPolicyId"}, | |
{ "messageImprint", 1073741826, "MessageImprint"}, | |
{ "serialNumber", 1073741827, NULL }, | |
{ "genTime", 1073741861, NULL }, | |
{ "accuracy", 1073758210, "Accuracy"}, | |
{ "ordering", 1610645508, NULL }, | |
{ NULL, 131081, NULL }, | |
{ "nonce", 1073758211, NULL }, | |
{ "tsa", 1610637314, "GeneralName"}, | |
{ NULL, 4104, "0"}, | |
{ "extensions", 536895490, "Extensions"}, | |
{ NULL, 4104, "1"}, | |
{ "Accuracy", 1610612741, NULL }, | |
{ "seconds", 1073758211, NULL }, | |
{ "millis", 1611161603, NULL }, | |
{ NULL, 1073745928, "0"}, | |
{ "1", 10, "999"}, | |
{ "micros", 537419779, NULL }, | |
{ NULL, 1073745928, "1"}, | |
{ "1", 10, "999"}, | |
{ "Extensions", 1612709899, NULL }, | |
{ "MAX", 1074266122, "1"}, | |
{ NULL, 2, "Extension"}, | |
{ "Extension", 1610612741, NULL }, | |
{ "extnID", 1073741836, NULL }, | |
{ "critical", 1610645508, NULL }, | |
{ NULL, 131081, NULL }, | |
{ "extnValue", 7, NULL }, | |
{ "AlgorithmIdentifier", 1610612741, NULL }, | |
{ "algorithm", 1073741836, NULL }, | |
{ "parameters", 541081613, NULL }, | |
{ "algorithm", 1, NULL }, | |
{ "PKIFreeText", 1612709899, NULL }, | |
{ "MAX", 1074266122, "1"}, | |
{ NULL, 34, NULL }, | |
{ "ContentInfo", 1610612741, NULL }, | |
{ "contentType", 1073741826, "ContentType"}, | |
{ "content", 541073421, NULL }, | |
{ NULL, 1073743880, "0"}, | |
{ "contentType", 1, NULL }, | |
{ "ContentType", 1073741836, NULL }, | |
{ "GeneralName", 1610612754, NULL }, | |
{ "otherName", 1610620930, "AnotherName"}, | |
{ NULL, 4104, "0"}, | |
{ "rfc822Name", 1610620957, NULL }, | |
{ NULL, 4104, "1"}, | |
{ "dNSName", 1610620957, NULL }, | |
{ NULL, 4104, "2"}, | |
{ "x400Address", 1610620930, "ORAddress"}, | |
{ NULL, 4104, "3"}, | |
{ "directoryName", 1610620930, "Name"}, | |
{ NULL, 4104, "4"}, | |
{ "ediPartyName", 1610620930, "EDIPartyName"}, | |
{ NULL, 4104, "5"}, | |
{ "uniformResourceIdentifier", 1610620957, NULL }, | |
{ NULL, 4104, "6"}, | |
{ "iPAddress", 1610620935, NULL }, | |
{ NULL, 4104, "7"}, | |
{ "registeredID", 536879116, NULL }, | |
{ NULL, 4104, "8"}, | |
{ "AnotherName", 1610612747, NULL }, | |
{ NULL, 13, NULL }, | |
{ "ORAddress", 1610612747, NULL }, | |
{ NULL, 13, NULL }, | |
{ "Name", 1610612747, NULL }, | |
{ NULL, 13, NULL }, | |
{ "EDIPartyName", 536870923, NULL }, | |
{ NULL, 13, NULL }, | |
{ NULL, 0, NULL } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment