1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 /* 21 * XSEC 22 * 23 * OpenSSLXSECCryptoKeyHMAC := HMAC Keys 24 * 25 * Author(s): Berin Lautenbach 26 * 27 * $Id: OpenSSLCryptoKeyHMAC.hpp 1817876 2017-12-12 01:27:14Z scantor $ 28 * 29 */ 30 31 #ifndef OPENSSLCRYPTOKEYHMAC_INCLUDE 32 #define OPENSSLCRYPTOKEYHMAC_INCLUDE 33 34 #include <xsec/enc/XSECCryptoKeyHMAC.hpp> 35 36 #if defined (XSEC_HAVE_OPENSSL) 37 38 /** 39 * \ingroup opensslcrypto 40 */ 41 42 /** 43 * \brief OpenSSL implementation for HMAC keys. 44 * 45 * Used to provide HMAC keys to OpenSSLCryptoHashHMAC 46 */ 47 48 class XSEC_EXPORT OpenSSLCryptoKeyHMAC : public XSECCryptoKeyHMAC { 49 50 public : 51 52 /** @name Constructors and Destructors */ 53 //@{ 54 55 OpenSSLCryptoKeyHMAC(); ~OpenSSLCryptoKeyHMAC()56 virtual ~OpenSSLCryptoKeyHMAC() {}; 57 58 //@} 59 60 /** @name Key Interface methods */ 61 //@{ 62 63 /** 64 * \brief Return the type of this key. 65 * 66 * For DSA keys, this allows people to determine whether this is a 67 * public key, private key or a key pair 68 */ 69 getKeyType() const70 virtual XSECCryptoKey::KeyType getKeyType() const {return KEY_HMAC;} 71 72 /** 73 * \brief Replicate key 74 */ 75 76 virtual XSECCryptoKey * clone() const; 77 78 /** 79 * \brief Return the OpenSSL string identifier 80 */ 81 82 virtual const XMLCh * getProviderName() const; 83 84 //@} 85 86 /** @name Optional Interface methods 87 * 88 * These functions do not necessarily have to be implmented. They 89 * are used by XSECKeyInfoResolverDefault to try to create a key from 90 * KeyInfo elements without knowing anything else. 91 * 92 * If an interface class does not implement these functions, a simple 93 * stub that does nothing should be used. 94 */ 95 //@{ 96 97 /** 98 * \brief Set the key 99 * 100 * Set the key from the buffer 101 * 102 * @param inBuf Buffer containing the key 103 * @param inLength Number of bytes of key in the buffer 104 * 105 * @note isSensitive() should have been called on the inbound buffer 106 * to ensure the contents is overwritten when the safeBuffer is deleted 107 */ 108 109 virtual void setKey(unsigned char * inBuf, unsigned int inLength); 110 111 /** 112 * \brief Get the key value 113 * 114 * Copy the key into the safeBuffer and return the number of bytes 115 * copied. 116 * 117 * @param outBuf Buffer to copy key into 118 * @returns number of bytes copied in 119 */ 120 121 virtual unsigned int getKey(safeBuffer &outBuf) const; 122 123 //@} 124 125 private: 126 127 safeBuffer m_keyBuf; 128 unsigned int m_keyLen; 129 }; 130 131 #endif /* XSEC_HAVE_OPENSSL */ 132 133 #endif /* OPENSSLCRYPTOKEYHMAC_INCLUDE */ 134