-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rework several functions to accept private key and password. - Add new function to parse private keys. - Add and update stubs accordingly. - Rework SslNative::InitHelper accordingly. - Update CMakes as required. - Update declaration or System.Net assembly. Signed-off-by: José Simões <jose.simoes@eclo.solutions>
- Loading branch information
1 parent
f81b05a
commit 63d5835
Showing
18 changed files
with
322 additions
and
78 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
38 changes: 38 additions & 0 deletions
38
...tem.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2.cpp
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,38 @@ | ||
// | ||
// Copyright (c) 2019 The nanoFramework project contributors | ||
// Portions Copyright (c) Microsoft Corporation. All rights reserved. | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
#include "sys_net_native.h" | ||
|
||
typedef Library_sys_net_native_System_Security_Cryptography_AsymmetricAlgorithm asymmetricAlgorithmType; | ||
|
||
HRESULT Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2::DecodePrivateKeyNative___STATIC__VOID__SZARRAY_U1__STRING( CLR_RT_StackFrame& stack ) | ||
{ | ||
NATIVE_PROFILE_CLR_NETWORK(); | ||
NANOCLR_HEADER(); | ||
|
||
CLR_RT_HeapBlock_Array* keyData = stack.Arg0().DereferenceArray(); | ||
CLR_UINT8* keyBuffer; | ||
CLR_RT_HeapBlock* passwordHb = stack.Arg1().DereferenceString(); | ||
const char* password; | ||
|
||
// get key buffer | ||
keyBuffer = keyData->GetFirstElement(); | ||
|
||
// manage password | ||
FAULT_ON_NULL_ARG(passwordHb); | ||
password = passwordHb->StringText(); | ||
|
||
if(SSL_DecodePrivateKey( | ||
(const unsigned char*)keyBuffer, | ||
keyData->m_numOfElements, | ||
(const unsigned char*)password, | ||
hal_strlen_s(password)) < 0) | ||
{ | ||
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); | ||
} | ||
|
||
NANOCLR_NOCLEANUP(); | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/PAL/COM/sockets/ssl/mbedTLS/ssl_decode_private_key_internal.cpp
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,40 @@ | ||
// | ||
// Copyright (c) 2018 The nanoFramework project contributors | ||
// Portions Copyright (c) Microsoft Corporation. All rights reserved. | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
#include "mbedtls.h" | ||
|
||
extern void SSL_GetCertDateTime_internal(DATE_TIME_INFO * dt, mbedtls_x509_time * mt ); | ||
|
||
int ssl_decode_private_key_internal( | ||
const unsigned char *key, | ||
size_t keyLength, | ||
const unsigned char *password, | ||
size_t passwordLength) | ||
{ | ||
mbedtls_pk_context pkey; | ||
|
||
int retCode; | ||
|
||
mbedtls_pk_init( &pkey ); | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// developer notes: // | ||
// this call parses certificates in both string and binary formats // | ||
// when the formart is a string it has to include the terminator otherwise the parse will fail // | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
retCode = mbedtls_pk_parse_key( | ||
&pkey, | ||
key, | ||
keyLength, | ||
password, | ||
passwordLength); | ||
|
||
|
||
// need to free this here | ||
mbedtls_pk_free( &pkey ); | ||
|
||
return retCode; | ||
} |
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.