Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit b2ecc1e

Browse files
committed
Merge pull request #329 from NETMF/fixCrypto
Add Crypto and fix OpenSSL
2 parents 3e22ce5 + d76bc26 commit b2ecc1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1281
-177
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
[Oo]bj/
3131
ipch/
3232

33+
!/tools/bin/
34+
3335
#uVision
3436
*.uvguix*
3537
Listings/

Application/TinyBooter/Commands.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,17 @@ bool Loader_Engine::Monitor_CheckSignature( WP_Message* msg )
14521452
return true;
14531453
}
14541454

1455+
#ifdef DEBUG
1456+
// dumps binary block in a form useable as C code constants for isolated testing and verification
1457+
void DumpBlockDeclaration( char const* name, UINT8 const* pBlock, size_t len )
1458+
{
1459+
debug_printf( "const char %s[] = {", name );
1460+
for( int i = 0; i < len; ++i )
1461+
debug_printf( "%c%d", i == 0 ? ' ' : ',', pBlock[ i ] );
1462+
debug_printf( "};\n" );
1463+
}
1464+
#endif
1465+
14551466
bool Loader_Engine::Monitor_SignatureKeyUpdate( WP_Message* msg )
14561467
{
14571468
bool fSuccess = false;
@@ -1486,13 +1497,23 @@ bool Loader_Engine::Monitor_SignatureKeyUpdate( WP_Message* msg )
14861497
ASSERT(0);
14871498
fSuccess = true;
14881499
}
1500+
else
1501+
{
1502+
#ifdef DEBUG
1503+
debug_printf( "Failed cert check for new key:\n");
1504+
DumpBlockDeclaration( "newKey", cmd->m_newKey, sizeof(RSAKey) );
1505+
DumpBlockDeclaration( "newKeySig", cmd->m_newKeySignature, sizeof( cmd->m_newKeySignature ) );
1506+
DumpBlockDeclaration( "currentKey", g_PrimaryConfigManager.GetDeploymentKeys( cmd->m_keyIndex ), sizeof(RSAKey) );
1507+
#endif
1508+
fSuccess = false;
1509+
}
14891510
}
14901511
}
14911512
}
14921513

14931514
ReplyToCommand( msg, fSuccess, false );
14941515

1495-
return true;
1516+
return true;
14961517
}
14971518

14981519
bool Loader_Engine::Monitor_FlashSectorMap( WP_Message* msg )

Application/TinyBooter/ConfigurationManager.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ void ConfigurationSectorManager::LocateConfigurationSector( UINT32 BlockUsage )
6868

6969
void ConfigurationSectorManager::LoadConfiguration()
7070
{
71-
if (m_device ==NULL) return;
71+
if (m_device ==NULL)
72+
return;
73+
7274
if (m_fSupportsXIP)
7375
{
7476
// Get the real address
@@ -91,7 +93,8 @@ void ConfigurationSectorManager::WriteConfiguration( UINT32 writeOffset, BYTE *d
9193
BOOL eraseWrite = FALSE;
9294
UINT32 writeLengthInBytes ;
9395

94-
if (m_device ==NULL) return ;
96+
if (m_device ==NULL)
97+
return ;
9598

9699
LoadConfiguration();
97100

@@ -179,9 +182,10 @@ void ConfigurationSectorManager::EraseWriteConfigBlock( BYTE * data, UINT32 size
179182

180183
BOOL ConfigurationSectorManager::IsBootLoaderRequired( INT32 &bootModeTimeout )
181184
{
182-
const UINT32 c_Empty = 0xFFFFFFFF;
185+
const UINT32 c_Empty = 0xFFFFFFFF;
183186

184-
if(m_device == NULL) return FALSE;
187+
if(m_device == NULL)
188+
return FALSE;
185189

186190
volatile UINT32* data = (volatile UINT32*)&m_configurationSector->BooterFlagArray[ 0 ];
187191

Application/TinyBooter/CryptoInterface.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44

55
#include "CryptoInterface.h"
66
#include "ConfigurationManager.h"
7-
//--//
87

98
extern UINT8* g_ConfigBuffer;
10-
extern int g_ConfigBufferLength;
11-
12-
13-
//--//
14-
9+
extern int g_ConfigBufferLength;
1510

1611
CryptoState::CryptoState( UINT32 dataAddress, UINT32 dataLength, BYTE* sig, UINT32 sigLength, UINT32 sectorType ) :
1712
#if defined(ARM_V1_2)
@@ -43,14 +38,16 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
4338
// IF THERE IS NO CONFIG SECTOR IN THE FLASH SECTOR TABLE, THEN WE DON'T HAVE KEYS,
4439
// THEREFORE WE WILL NOT PERFORM SIGNATURE CHECKING.
4540
//
46-
if(g_PrimaryConfigManager.m_device == NULL) return true;
41+
if(g_PrimaryConfigManager.m_device == NULL)
42+
return true;
4743

4844

4945
switch(m_sectorType)
5046
{
5147
case BlockRange::BLOCKTYPE_DEPLOYMENT:
5248
// backwards compatibility
53-
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter) return true;
49+
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter)
50+
return true;
5451

5552
// if there is no key then we do not need to check the signature for the deployment sectors ONLY
5653
if(g_PrimaryConfigManager.CheckSignatureKeyEmpty( ConfigurationSector::c_DeployKeyDeployment ))
@@ -73,10 +70,11 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
7370
ASSERT(g_ConfigBufferLength > 0);
7471
ASSERT(g_ConfigBuffer != NULL);
7572

76-
if(g_ConfigBuffer == NULL || g_ConfigBufferLength <= 0) return false;
73+
if(g_ConfigBuffer == NULL || g_ConfigBufferLength <= 0)
74+
return false;
7775

7876
// the g_ConfigBuffer contains the new configuration data
79-
const ConfigurationSector* pNewCfg = (const ConfigurationSector*)g_ConfigBuffer;
77+
const ConfigurationSector* pNewCfg = (const ConfigurationSector*)g_ConfigBuffer;
8078

8179
bool fCanWrite = false;
8280
bool fRet = false;
@@ -125,7 +123,8 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
125123
// backwards compatibility
126124

127125

128-
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter) return true;
126+
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter)
127+
return true;
129128

130129
// if there is no key then we do not need to check the signature for the deployment sectors ONLY
131130
if (g_PrimaryConfigManager.CheckSignatureKeyEmpty( keyIndex ))
@@ -136,7 +135,6 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
136135
key = (RSAKey*)g_PrimaryConfigManager.GetDeploymentKeys( keyIndex );
137136

138137
break;
139-
140138
};
141139

142140
if(key == NULL)
@@ -151,7 +149,7 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
151149
{
152150
m_res = ::Crypto_StepRSAOperation( &m_handle );
153151
}
154-
152+
155153
return m_res == CRYPTO_SUCCESS;
156154
}
157155

CLR/Core/Execution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ bool CLR_RT_ExecutionEngine::SpawnStaticConstructorHelper( CLR_RT_AppDomain* app
840840
CLR_RT_MethodDef_Index idxNext;
841841

842842
_ASSERTE(m_cctorThread != NULL);
843-
_ASSERTE(m_cctorThread->CanThreadBeReused());
843+
//_ASSERTE(m_cctorThread->CanThreadBeReused());
844844

845845
idxNext.m_data = idx.m_data;
846846

DeviceCode/pal/OpenSSL/OpenSSL_1_0_0/tinyclr/ssl_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ typedef int ssize_t;
109109
#define EWOULDBLOCK EAGAIN
110110
#endif
111111

112-
#ifndef WSAEWOULDBLOCK
113-
#define WSAEWOULDBLOCK EWOULDBLOCK
114-
#endif
115-
116112
#define SIGINT 4 // attention request from user from signal.h
117113

118114
#ifdef BUFSIZ

0 commit comments

Comments
 (0)