-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand
SSLSessionId
structure to manage allocated memory. (#1614)
!!! Possible breaking changes !!! struct SSLKeyCertPair -> class SslKeyCertPair certificate -> getCertificate() certificateLength -> getCertificateLength() key -> getKey() keyLength -> getKeyLength() struct SSLSessionId -> class SslSessionId value -> getValue() length -> getLength() SSLFingerprintType -> SslFingerprintType Deprecated so old version still works with compiler warning: SSLFingerprints -> SslFingerprints SSLKeyCertPair -> SslKeyCertPair SSLSessionId -> SslSessionId * Expand `SSLSessionId` structure to manage allocated memory. * Split SSL structures into separate files * Put all SSL files into `Ssl` sub-folder and create common `SslStructs.h` * Rename structures from `SSL*` to `Ssl*` for consistency SSLFingerprints -> SslFingerprints SSLKeyCertPair -> SslKeyCertPair SSL SessionId -> SslSessionId Definitions included for old versions but will generate compiler warning. * Revised `SslKeyCertPair` and `SslSessionId` to use `String` for storage Change from `struct` to `class`. Data no longer directly accessible.
- Loading branch information
Showing
17 changed files
with
254 additions
and
181 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/**** | ||
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. | ||
* Created 2015 by Skurydin Alexey | ||
* http://github.com/anakod/Sming | ||
* All files of the Sming Core are provided under the LGPL v3 license. | ||
****/ | ||
|
||
#include "ssl/ssl.h" | ||
|
||
enum SslFingerprintType { | ||
eSFT_CertSha1 = 0, // << Fingerprint based on the SHA1 value of the certificate. | ||
// Every time a certificate is renewed this value will change. | ||
eSFT_PkSha256, // << Fingerprint based on the SHA256 value of the public key subject in the certificate. | ||
// Only when the private key used to generate the certificate is used then that fingerprint | ||
}; | ||
|
||
typedef struct { | ||
uint8_t* certSha1 = nullptr; // << certificate SHA1 fingerprint | ||
uint8_t* pkSha256 = nullptr; // << public key SHA256 fingerprint | ||
|
||
void free() | ||
{ | ||
delete certSha1; | ||
certSha1 = nullptr; | ||
delete pkSha256; | ||
pkSha256 = nullptr; | ||
} | ||
} SslFingerprints; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/**** | ||
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. | ||
* Created 2015 by Skurydin Alexey | ||
* http://github.com/anakod/Sming | ||
* All files of the Sming Core are provided under the LGPL v3 license. | ||
****/ | ||
|
||
#ifndef SMINGCORE_NETWORK_SSLKEYCERTPAIR_H_ | ||
#define SMINGCORE_NETWORK_SSLKEYCERTPAIR_H_ | ||
|
||
#include "ssl/ssl.h" | ||
#include "WString.h" | ||
|
||
/** @brief Class to manage an SSL key certificate with optional password | ||
*/ | ||
class SslKeyCertPair | ||
{ | ||
public: | ||
bool isValid() | ||
{ | ||
return key && certificate; | ||
} | ||
|
||
/** @brief Create certificate using provided values | ||
* @param newKey | ||
* @param newKeyLength | ||
* @param newCertificate | ||
* @param newCertificateLength | ||
* @param newKeyPassword | ||
* @retval bool false on memory allocation failure | ||
* @note We take a new copy of the certificate | ||
*/ | ||
bool assign(const uint8_t* newKey, unsigned newKeyLength, const uint8_t* newCertificate, | ||
unsigned newCertificateLength, const char* newKeyPassword = nullptr) | ||
{ | ||
free(); | ||
|
||
if(newKeyLength != 0 && newKey != nullptr) { | ||
if(!key.setLength(newKeyLength)) { | ||
return false; | ||
} | ||
memcpy(key.begin(), newKey, newKeyLength); | ||
} | ||
|
||
if(newCertificateLength != 0 && newCertificate != nullptr) { | ||
if(!certificate.setLength(newCertificateLength)) { | ||
return false; | ||
} | ||
memcpy(certificate.begin(), newCertificate, newCertificateLength); | ||
} | ||
|
||
unsigned passwordLength = (newKeyPassword == nullptr) ? 0 : strlen(newKeyPassword); | ||
if(passwordLength != 0) { | ||
keyPassword.setString(newKeyPassword, passwordLength); | ||
if(!keyPassword) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** @brief Assign another certificate to this structure | ||
* @param keyCert | ||
* @retval bool false on memory allocation failure | ||
* @note We take a new copy of the certificate | ||
*/ | ||
bool assign(const SslKeyCertPair& keyCert) | ||
{ | ||
*this = keyCert; | ||
return (key == keyCert.key) && (keyPassword == keyCert.keyPassword) && (certificate == keyCert.certificate); | ||
} | ||
|
||
void free() | ||
{ | ||
key = nullptr; | ||
keyPassword = nullptr; | ||
certificate = nullptr; | ||
} | ||
|
||
const uint8_t* getKey() | ||
{ | ||
return reinterpret_cast<const uint8_t*>(key.c_str()); | ||
} | ||
|
||
unsigned getKeyLength() | ||
{ | ||
return key.length(); | ||
} | ||
|
||
const char* getKeyPassword() | ||
{ | ||
return keyPassword.c_str(); | ||
} | ||
|
||
const uint8_t* getCertificate() | ||
{ | ||
return reinterpret_cast<const uint8_t*>(certificate.c_str()); | ||
} | ||
|
||
unsigned getCertificateLength() | ||
{ | ||
return certificate.length(); | ||
} | ||
|
||
private: | ||
String key; | ||
String keyPassword; | ||
String certificate; | ||
}; | ||
|
||
#endif /* SMINGCORE_NETWORK_SSLKEYCERTPAIR_H_ */ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/**** | ||
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. | ||
* Created 2015 by Skurydin Alexey | ||
* http://github.com/anakod/Sming | ||
* All files of the Sming Core are provided under the LGPL v3 license. | ||
****/ | ||
|
||
#ifndef SMINGCORE_NETWORK_SSLSESSIONID_H_ | ||
#define SMINGCORE_NETWORK_SSLSESSIONID_H_ | ||
|
||
#include "ssl/ssl.h" | ||
#include "WString.h" | ||
|
||
/** @brief Manages buffer to store SSL Session ID | ||
*/ | ||
class SslSessionId | ||
{ | ||
public: | ||
/** @brief May be called even when object is null */ | ||
const uint8_t* getValue() | ||
{ | ||
return this ? reinterpret_cast<const uint8_t*>(value.c_str()) : nullptr; | ||
} | ||
|
||
/** @brief May be called even when object is null */ | ||
unsigned getLength() | ||
{ | ||
return this ? value.length() : 0; | ||
} | ||
|
||
bool isValid() | ||
{ | ||
return getLength() != 0; | ||
} | ||
|
||
bool assign(const uint8_t* newValue, unsigned newLength) | ||
{ | ||
if(!value.setLength(newLength)) { | ||
return false; | ||
} | ||
memcpy(value.begin(), newValue, newLength); | ||
return true; | ||
} | ||
|
||
private: | ||
String value; | ||
}; | ||
|
||
#endif /* SMINGCORE_NETWORK_SSLSESSIONID_H_ */ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/**** | ||
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. | ||
* Created 2015 by Skurydin Alexey | ||
* http://github.com/anakod/Sming | ||
* All files of the Sming Core are provided under the LGPL v3 license. | ||
****/ | ||
|
||
#ifndef SMINGCORE_NETWORK_SSL_SSLSTRUCTS_H_ | ||
#define SMINGCORE_NETWORK_SSL_SSLSTRUCTS_H_ | ||
|
||
#include "SslFingerprints.h" | ||
#include "SslKeyCertPair.h" | ||
#include "SslSessionId.h" | ||
|
||
/* | ||
* These structures have been renamed, please use the revised convention SslXXX | ||
*/ | ||
typedef SslKeyCertPair SSLKeyCertPair __attribute__((deprecated)); | ||
typedef SslSessionId SSLSessionId __attribute__((deprecated)); | ||
typedef SslFingerprints SSLFingerprints __attribute__((deprecated)); | ||
|
||
#endif /* SMINGCORE_NETWORK_SSL_SSLSTRUCTS_H_ */ |
File renamed without changes.
File renamed without changes.
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
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
Oops, something went wrong.