You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2004/04/19 12:54:46 UTC

cvs commit: xml-security/c/src/enc XSECCryptoX509.cpp XSECCryptoX509.hpp

blautenb    2004/04/19 03:54:46

  Modified:    c/src/enc XSECCryptoX509.hpp
  Added:       c/src/enc XSECCryptoX509.cpp
  Log:
  Build a cert from PEM encoded input
  
  Revision  Changes    Path
  1.9       +13 -1     xml-security/c/src/enc/XSECCryptoX509.hpp
  
  Index: XSECCryptoX509.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/enc/XSECCryptoX509.hpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XSECCryptoX509.hpp	8 Feb 2004 10:23:57 -0000	1.8
  +++ XSECCryptoX509.hpp	19 Apr 2004 10:54:46 -0000	1.9
  @@ -103,6 +103,18 @@
   	virtual void loadX509Base64Bin(const char * buf, unsigned int len) = 0;
   
   	/**
  +	 * \brief Load a PEM encoded certificate into the object.
  +	 *
  +	 * Take a PEM encoded certificate and load.
  +	 *
  +	 * @param buf A buffer containing the PEM encoded certificate
  +	 * @param len The number of bytes of data in the certificate.
  +	 * (0 if the string is null terminated.)
  +	 */
  +
  +	void loadX509PEM(const char * buf, unsigned int len = 0);
  +
  +	/**
   	 * \brief Get a Base64 DER encoded copy of the certificate
   	 *
   	 * @returns A safeBuffer containing the DER encoded certificate
  
  
  
  1.1                  xml-security/c/src/enc/XSECCryptoX509.cpp
  
  Index: XSECCryptoX509.cpp
  ===================================================================
  /*
   * Copyright 2002-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * imitations under the License.
   */
  
  /*
   * XSEC
   *
   * XSECCryptoX509:= A base class for handling X509 (V3) certificates
   *
   * $Id: XSECCryptoX509.cpp,v 1.1 2004/04/19 10:54:46 blautenb Exp $
   *
   */
  
  #include <xsec/framework/XSECDefs.hpp>
  #include <xsec/enc/XSECCryptoX509.hpp>
  #include <xsec/framework/XSECError.hpp>
  #include <xsec/enc/XSECCryptoException.hpp>
  
  void XSECCryptoX509::loadX509PEM(const char * buf, unsigned int len) {
  
  	const char * b;
  	char * b1 = NULL;
  	if (len == 0)
  		b = buf;
  	else {
  		XSECnew(b1, char[len+1]);
  		memcpy(b1, buf, len);
  		b1[len] = '\0';
  		b = b1;
  	}
  
  	char *p = strstr(buf, "-----BEGIN CERTIFICATE-----");
  
  	if (p == NULL) {
  
  		if (b1 != NULL)
  			delete[] b1;
  
  		throw XSECCryptoException(XSECCryptoException::X509Error,
  		"X509::loadX509PEM - Cannot find start of PEM certificate");
  
  	}
  
  	p += strlen("-----BEGIN CERTIFICATE-----");
  
  	while (*p == '\n' || *p == '\r' || *p == '-')
  		p++;
  
  	safeBuffer output;
  	int i = 0;
  	while (*p != '\0' && *p != '-') {
  		output[i++] = *p;
  		++p;
  	}
  
  	if (strstr(p, "-----END CERTIFICATE-----") != p) {
  
  		if (b1 != NULL)
  			delete[] b1;
  
  		throw XSECCryptoException(XSECCryptoException::X509Error,
  		"X509::loadX509PEM - Cannot find end of PEM certificate");
  
  	}
  	
  	if (b1 != NULL)
  		delete[] b1;
  
  	output[i] = '\0';
  
  	this->loadX509Base64Bin(output.rawCharBuffer(), i);
  
  }