# $Id$ # # Copyright (C) 2014 Dragon Research Labs ("DRL") # Portions copyright (C) 2009--2013 Internet Systems Consortium ("ISC") # Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notices and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND DRL, ISC, AND ARIN DISCLAIM ALL # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL, # ISC, OR ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ Exception definitions for RPKI modules. """ class RPKI_Exception(Exception): "Base class for RPKI exceptions." class NotInDatabase(RPKI_Exception): "Lookup failed for an object expected to be in the database." class BadURISyntax(RPKI_Exception): "Illegal syntax for a URI." class BadStatusCode(RPKI_Exception): "Unrecognized protocol status code." class BadQuery(RPKI_Exception): "Unexpected protocol query." class DBConsistancyError(RPKI_Exception): "Found multiple matches for a database query that shouldn't ever return that." class CMSVerificationFailed(RPKI_Exception): "Verification of a CMS message failed." class HTTPRequestFailed(RPKI_Exception): "HTTP request failed." class DERObjectConversionError(RPKI_Exception): "Error trying to convert a DER-based object from one representation to another." class NotACertificateChain(RPKI_Exception): "Certificates don't form a proper chain." class BadContactURL(RPKI_Exception): "Error trying to parse contact URL." class BadClassNameSyntax(RPKI_Exception): "Illegal syntax for a class_name." class BadIssueResponse(RPKI_Exception): "issue_response PDU with wrong number of classes or certificates." class NotImplementedYet(RPKI_Exception): "Internal error -- not implemented yet." class BadPKCS10(RPKI_Exception): "Bad PKCS #10 object." class UpstreamError(RPKI_Exception): "Received an error from upstream." class ChildNotFound(RPKI_Exception): "Could not find specified child in database." class BSCNotFound(RPKI_Exception): "Could not find specified BSC in database." class BadSender(RPKI_Exception): "Unexpected XML sender value." class ClassNameMismatch(RPKI_Exception): "class_name does not match child context." class ClassNameUnknown(RPKI_Exception): "Unknown class_name." class SKIMismatch(RPKI_Exception): "SKI value in response does not match request." class SubprocessError(RPKI_Exception): "Subprocess returned unexpected error." class BadIRDBReply(RPKI_Exception): "Unexpected reply to IRDB query." class NotFound(RPKI_Exception): "Object not found in database." class MustBePrefix(RPKI_Exception): "Resource range cannot be expressed as a prefix." class TLSValidationError(RPKI_Exception): "TLS certificate validation error." class MultipleTLSEECert(TLSValidationError): "Received more than one TLS EE certificate." class ReceivedTLSCACert(TLSValidationError): "Received CA certificate via TLS." class WrongEContentType(RPKI_Exception): "Received wrong CMS eContentType." class EmptyPEM(RPKI_Exception): "Couldn't find PEM block to convert." class UnexpectedCMSCerts(RPKI_Exception): "Received CMS certs when not expecting any." class UnexpectedCMSCRLs(RPKI_Exception): "Received CMS CRLs when not expecting any." class MissingCMSEEcert(RPKI_Exception): "Didn't receive CMS EE cert when expecting one." class MissingCMSCRL(RPKI_Exception): "Didn't receive CMS CRL when expecting one." class UnparsableCMSDER(RPKI_Exception): "Alleged CMS DER wasn't parsable." class CMSCRLNotSet(RPKI_Exception): "CMS CRL has not been configured." class ServerShuttingDown(RPKI_Exception): "Server is shutting down." class NoActiveCA(RPKI_Exception): "No active ca_detail for specified class." class BadClientURL(RPKI_Exception): "URL given to HTTP client does not match profile." class ClientNotFound(RPKI_Exception): "Could not find specified client in database." class BadExtension(RPKI_Exception): "Forbidden X.509 extension." class ForbiddenURI(RPKI_Exception): "Forbidden URI, does not start with correct base URI." class HTTPClientAborted(RPKI_Exception): "HTTP client connection closed while in request-sent state." class BadPublicationReply(RPKI_Exception): "Unexpected reply to publication query." class DuplicateObject(RPKI_Exception): "Attempt to create an object that already exists." class EmptyROAPrefixList(RPKI_Exception): "Can't create ROA with an empty prefix list." class NoCoveringCertForROA(RPKI_Exception): "Couldn't find a covering certificate to generate ROA." class BSCNotReady(RPKI_Exception): "BSC not yet in a usable state, signing_cert not set." class HTTPUnexpectedState(RPKI_Exception): "HTTP event occurred in an unexpected state." class HTTPBadVersion(RPKI_Exception): "HTTP couldn't parse HTTP version." class HandleTranslationError(RPKI_Exception): "Internal error translating protocol handle -> SQL id." class NoObjectAtURI(RPKI_Exception): "No object published at specified URI." class ExistingObjectAtURI(RPKI_Exception): "An object has already been published at specified URI." class DifferentObjectAtURI(RPKI_Exception): "An object with a different hash exists at specified URI." class CMSContentNotSet(RPKI_Exception): """ Inner content of a CMS_object has not been set. If object is known to be valid, the .extract() method should be able to set the content; otherwise, only the .verify() method (which checks signatures) is safe. """ class HTTPTimeout(RPKI_Exception): "HTTP connection timed out." class BadIPResource(RPKI_Exception): "Parse failure for alleged IP resource string." class BadROAPrefix(RPKI_Exception): "Parse failure for alleged ROA prefix string." class CommandParseFailure(RPKI_Exception): "Failed to parse command line." class CMSCertHasExpired(RPKI_Exception): "CMS certificate has expired." class TrustedCMSCertHasExpired(RPKI_Exception): "Trusted CMS certificate has expired." class MultipleCMSEECert(RPKI_Exception): "Can't have more than one CMS EE certificate in validation chain." class ResourceOverlap(RPKI_Exception): "Overlapping resources in resource_set." class CMSReplay(RPKI_Exception): "Possible CMS replay attack detected." class PastNotAfter(RPKI_Exception): "Requested notAfter value is already in the past." class NullValidityInterval(RPKI_Exception): "Requested validity interval is null." class BadX510DN(RPKI_Exception): "X.510 distinguished name does not match profile." class BadAutonomousSystemNumber(RPKI_Exception): "Bad AutonomousSystem number." class WrongEKU(RPKI_Exception): "Extended Key Usage extension does not match profile." class UnexpectedUpDownResponse(RPKI_Exception): "Up-down message is not of the expected type." class BadContentType(RPKI_Exception): "Bad HTTP Content-Type." class ResourceClassMismatch(RPKI_Exception): "Up-down resource class does not match." class IRDBExpired(RPKI_Exception): "Back-end database record has expired." ='n138' href='#n138'>138 139 140
/* dsa_asn1.c */
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
 * project 2000.
 */
/* ====================================================================
 * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. 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.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
 *
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    licensing@OpenSSL.org.
 *
 * 5. Products derived from this software may not be called "OpenSSL"
 *    nor may "OpenSSL" appear in their names without prior written
 *    permission of the OpenSSL Project.
 *
 * 6. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
 *
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
 * EXPRESSED 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 OpenSSL PROJECT OR
 * ITS 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.
 * ====================================================================
 *
 * This product includes cryptographic software written by Eric Young
 * (eay@cryptsoft.com).  This product includes software written by Tim
 * Hudson (tjh@cryptsoft.com).
 *
 */

#include <stdio.h>
#include "cryptlib.h"
#include <openssl/dsa.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>

/* Override the default new methods */
static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
{
	if(operation == ASN1_OP_NEW_PRE) {
		DSA_SIG *sig;
		sig = OPENSSL_malloc(sizeof(DSA_SIG));
		sig->r = NULL;
		sig->s = NULL;
		*pval = (ASN1_VALUE *)sig;
		if(sig) return 2;
		DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
		return 0;
	}
	return 1;
}

ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
	ASN1_SIMPLE(DSA_SIG, r, CBIGNUM),
	ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)

IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG)

/* Override the default free and new methods */
static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
{
	if(operation == ASN1_OP_NEW_PRE) {
		*pval = (ASN1_VALUE *)DSA_new();
		if(*pval) return 2;
		return 0;
	} else if(operation == ASN1_OP_FREE_PRE) {
		DSA_free((DSA *)*pval);
		*pval = NULL;
		return 2;
	}
	return 1;
}

ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
	ASN1_SIMPLE(DSA, version, LONG),
	ASN1_SIMPLE(DSA, p, BIGNUM),
	ASN1_SIMPLE(DSA, q, BIGNUM),
	ASN1_SIMPLE(DSA, g, BIGNUM),
	ASN1_SIMPLE(DSA, pub_key, BIGNUM),
	ASN1_SIMPLE(DSA, priv_key, BIGNUM)
} ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)

IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPrivateKey, DSAPrivateKey)

ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
	ASN1_SIMPLE(DSA, p, BIGNUM),
	ASN1_SIMPLE(DSA, q, BIGNUM),
	ASN1_SIMPLE(DSA, g, BIGNUM),
} ASN1_SEQUENCE_END_cb(DSA, DSAparams)

IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams)

/* DSA public key is a bit trickier... its effectively a CHOICE type
 * decided by a field called write_params which can either write out
 * just the public key as an INTEGER or the parameters and public key
 * in a SEQUENCE
 */

ASN1_SEQUENCE(dsa_pub_internal) = {
	ASN1_SIMPLE(DSA, pub_key, BIGNUM),
	ASN1_SIMPLE(DSA, p, BIGNUM),
	ASN1_SIMPLE(DSA, q, BIGNUM),
	ASN1_SIMPLE(DSA, g, BIGNUM)
} ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal)

ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
	ASN1_SIMPLE(DSA, pub_key, BIGNUM),
	ASN1_EX_COMBINE(0, 0, dsa_pub_internal)
} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)

IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)