Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
bcf75e2
Added certificate extensions that that permit automaic chain building
LordOfDorks Sep 27, 2017
e4e8dee
Fixed a size issue with the KeyUsage property.
LordOfDorks Sep 28, 2017
cac0a5a
This tool will generate a .P7B certificate store from one or more PEM…
LordOfDorks Sep 29, 2017
3cdaf93
Made reading files fail with more grace.
LordOfDorks Sep 29, 2017
f9cfac6
Fixed a pointer bug and CA key usage properties so Windows likes the …
LordOfDorks Oct 11, 2017
68daf66
Ensure that serial number cannot have a leading zero.
LordOfDorks Oct 12, 2017
bec29c4
In progress: CyReP implementation on STM32L476 (SensorTile or Nucleo-64)
LordOfDorks Oct 20, 2017
e40c727
Created agent project
LordOfDorks Oct 21, 2017
30afd8c
Refactoring and sharing code between BootLdr and Trusted Agent.
LordOfDorks Oct 22, 2017
9f45e34
Added Agent Header structure to TA.
LordOfDorks Oct 22, 2017
548781d
BarT.exe can now SIGN an agent *.hex file.
LordOfDorks Oct 24, 2017
5dd174d
Making CyReP compile on GNU ARM
LordOfDorks Oct 31, 2017
196b148
Making the Emulator copmile on GNU for ARM.
LordOfDorks Nov 1, 2017
d184f09
Continuing to fix the library for i.MX6
LordOfDorks Nov 1, 2017
02d4de1
Final batch of changes.
LordOfDorks Nov 1, 2017
86ab04b
fixed the bool problem. Again.
LordOfDorks Nov 1, 2017
c2a782c
Fixed include brackets.
LordOfDorks Nov 1, 2017
87be8c2
Consolidated CyReP source location.
LordOfDorks Nov 1, 2017
8155e10
Rebased the header locations.
LordOfDorks Nov 1, 2017
5d0cf3e
Folding in STM32 requirements.
LordOfDorks Nov 1, 2017
2cd8adb
Stm32 uses published sources now.
LordOfDorks Nov 2, 2017
b5abe4f
Jordan feedback worked in.
LordOfDorks Nov 2, 2017
c82aa4e
More header juggling.
LordOfDorks Nov 2, 2017
a6550ae
BarT fallout.
LordOfDorks Nov 2, 2017
da9eeb8
Yet more header magic.
LordOfDorks Nov 2, 2017
ddb6c7b
Fallout for STM32
LordOfDorks Nov 2, 2017
0446e62
More review feedback.
LordOfDorks Nov 2, 2017
bfd4dcd
SIGN Testvector for BarT
LordOfDorks Nov 3, 2017
288809b
Changes to Barnacle structures.
LordOfDorks Nov 7, 2017
8844124
Merge branch 'master' of https://github.com/LordOfDorks/RIoT.git
LordOfDorks Nov 7, 2017
a455364
fallout for BarT.
LordOfDorks Nov 7, 2017
0cda0e1
Fixed flash layout issue.
LordOfDorks Nov 7, 2017
f714620
Boot preparation done.
LordOfDorks Nov 12, 2017
7f3ef8f
Switching devboxes
LordOfDorks Nov 17, 2017
bb2429e
Secure updating and debugging into the agent is working!
LordOfDorks Nov 18, 2017
e692f74
Firewall operational.
LordOfDorks Nov 29, 2017
5bc2e2f
Barnacle fully working and secure in debug mode.
LordOfDorks Dec 6, 2017
119f069
Barnacle ready for integration.
LordOfDorks Dec 9, 2017
7a41c5e
Adding Brian's CBOR changes.
LordOfDorks Dec 22, 2017
04f85c2
Incorporated fallout from BriTel's TCPS CBOR changes
LordOfDorks Jan 4, 2018
0ad709e
Minor changes to header to combat naming conflicts with other stacks.…
Britel Jan 5, 2018
a72c883
Barnacle is supporting CBOR formatted TCPS data sheets.
LordOfDorks Jan 5, 2018
869623f
Build error: Fixed ESSExport call
Britel Jan 5, 2018
f639fab
Barnacle is ready for issued identities.
LordOfDorks Jan 5, 2018
62e615c
Fixee size of DER encoded EccPrv
Britel Jan 6, 2018
bdb2bf5
Identity blob can be successfully written back to Barnacle.
LordOfDorks Jan 6, 2018
cc681b8
BarT issues device certificates, CBOR blob update
LordOfDorks Jan 10, 2018
c160abb
DeviceID display. PEM formatted public keys.
LordOfDorks Jan 10, 2018
25b0eee
Merged PR 153: Merge user/britel/riot-10.01.18-update to master
Britel Jan 12, 2018
157889b
Merge branch 'master' into dev/TCPS-working
Britel Jan 12, 2018
5da19cc
Removed duplicate function
Britel Jan 12, 2018
c43b37c
Fix OPTEE build error
Jan 12, 2018
f6b02c9
Merged PR 156: Fix OPTEE build error
danmihai1 Jan 12, 2018
904e0e2
Added ModifyTCPSDeviceIdentity
Britel Jan 13, 2018
551129e
github remote merge/master
Britel Jan 13, 2018
0fa9974
TcpsID: added ver
Britel Jan 16, 2018
6042a9b
Removed heap allocation. API requires buffer to be pre-allocated
Britel Jan 16, 2018
7e650c8
Moved common define
Britel Jan 16, 2018
b85a40d
Fixed Barnacale build errors due to API change
Britel Jan 16, 2018
b2256f3
Moved tinycbor back to v0.4.1 to get around x86 build failure. Update…
Britel Jan 18, 2018
8451812
Completed TCPS ID integration and device certificate issuing.
LordOfDorks Jan 24, 2018
12c4964
Fixed the Alias cert generation to match the device one.
LordOfDorks Jan 24, 2018
c109e92
Fixed the broken gitignore and added two missing source files
LordOfDorks Feb 21, 2018
f924383
Incoming TCPS changes (#4)
Britel Jul 13, 2018
84ffe25
Tcps cbor update, x509 CSR OID extension, and CyReP bug fixes (#5)
Britel Jul 17, 2018
8108ab7
Cleanup. set CBOR_NO_PRETTY_API for compilation in SGX/OPTEE
Britel Jul 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "External/tinycbor"]
path = External/tinycbor
url = https://github.com/intel/tinycbor.git
branch = dev
10 changes: 4 additions & 6 deletions Emulator/RIoT/RIoTCrypt/RiotAes128.c → CyReP/RiotAes128.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************************/

//
// 4-MAY-2015; RIoT adaptation (DennisMa;MSFT)
//
#include "RiotTarget.h"
#include "RiotAes128.h"
#include <RiotTarget.h>
#include <RiotAes128.h>

// This file contains data tables and is not supposed to be compiled on it's own
#define _AES_COMPILE_
#include "RiotAesTables.c"

Expand Down Expand Up @@ -225,7 +223,7 @@ void RIOT_AES_CBC_128_ENCRYPT(const aes128EncryptKey_t *aes128EncryptKey,

#if AES_ECB_MODE
void RIOT_AES_ECB_128_ENCRYPT(const aes128EncryptKey_t *aes128EncryptKey,
const uint8_t *in, uint8_t *out, size_t size)
const uint8_t *in, uint8_t *out, uint32_t size)
{
uint32_t in32[4];
uint32_t out32[4];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************************/

//
// 4-MAY-2015; RIoT adaptation (DennisMa;MSFT).
//
// This file contains AES data tables and is not supposed to be compiled on it's own

#ifdef _AES_COMPILE_

Expand Down Expand Up @@ -129,7 +127,7 @@ static const uint32_t Rconst[12] = {

#else

#include "stdint.h"
#include <stdint.h>
extern const uint32_t ftable[];

#endif
28 changes: 20 additions & 8 deletions Emulator/RIoT/RIoTCrypt/RiotBase64.c → CyReP/RiotBase64.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#include <stdint.h>
#include <string.h>
#include "RiotBase64.h"
#include <RiotTarget.h>
#include <RiotBase64.h>

#define splitInt(intVal, bytePos) (char)((intVal >> (bytePos << 3)) & 0xFF)
#define joinChars(a, b, c, d) (uint32_t)((uint32_t)a + \
Expand Down Expand Up @@ -246,8 +245,11 @@ Base64Encode(
// Calculate required output buffer length in bytes
reqSize = (Length == 0) ? (0) : ((((Length - 1) / 3) + 1) * 4);

// Plus trailing NULL
reqSize += 1;
// CRLFs after 64 characters
reqSize += (reqSize / 64) * 2;

// Plus trailing CR&NL
reqSize += 2;

// Validate length of output buffer
if (OutLen && (*OutLen < reqSize)) {
Expand All @@ -259,6 +261,7 @@ Base64Encode(
// b0 b1(+1) b2(+2)
// 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
// |----c1---| |----c2---| |----c3---| |----c4---|
uint32_t line = 0;
while (Length - curPos >= 3)
{
char c1 = base64char(Input[curPos] >> 2);
Expand All @@ -273,7 +276,13 @@ Base64Encode(
Output[dstPos++] = c2;
Output[dstPos++] = c3;
Output[dstPos++] = c4;

line += 4;
if((line % 64) == 0)
{
Output[dstPos++] = '\r';
Output[dstPos++] = '\n';
line = 0;
}
}

if (Length - curPos == 2)
Expand All @@ -287,6 +296,7 @@ Base64Encode(
Output[dstPos++] = c2;
Output[dstPos++] = c3;
Output[dstPos++] = '=';
line += 4;
}
else if (Length - curPos == 1)
{
Expand All @@ -297,10 +307,12 @@ Base64Encode(
Output[dstPos++] = c2;
Output[dstPos++] = '=';
Output[dstPos++] = '=';
line += 4;
}

// Add NL termination
Output[dstPos] = '\n';
// Add CR&NL termination
Output[dstPos++] = '\r';
Output[dstPos++] = '\n';

// Output buffer length
if (OutLen) {
Expand Down
38 changes: 32 additions & 6 deletions Emulator/RIoT/RIoTCrypt/RiotCrypt.c → CyReP/RiotCrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ Microsoft Copyright 2017
Confidential Information

*/
#include "RiotCrypt.h"
#include <RiotTarget.h>
#include <RiotStatus.h>
#include <RiotSha256.h>
#include <RiotHmac.h>
#include <RiotKdf.h>
#include <RiotEcc.h>
#include <RiotAes128.h>
#include <RiotCrypt.h>

#define RIOT_MAX_KDF_FIXED_SIZE RIOT_MAX_KDF_CONTEXT_LENGTH + \
RIOT_MAX_KDF_LABEL_LENGTH + 5
Expand Down Expand Up @@ -164,7 +171,7 @@ RiotCrypt_DeriveEccKey(
size_t labelSize // IN: TODO
)
{
bigval_t srcVal = { 0 };
bigval_t srcVal = { { 0 } };
bigval_t *pSrcVal = NULL;

if (srcDataSize > sizeof(bigval_t)) {
Expand All @@ -182,11 +189,31 @@ RiotCrypt_DeriveEccKey(
pSrcVal, label, labelSize);
}

RIOT_STATUS
RiotCrypt_ImportEccPub(
uint8_t *b, // IN: TODO
uint32_t s, // IN: TODO
ecc_publickey *a // OUT: TODO
)
{
if ((*b++ != 0x04) ||
(s < 1 + 2 * RIOT_ECC_COORD_BYTES))
{
return RIOT_INVALID_PARAMETER;
}

BigIntToBigVal(&a->x, b, RIOT_ECC_COORD_BYTES);
b += RIOT_ECC_COORD_BYTES;
BigIntToBigVal(&a->y, b, RIOT_ECC_COORD_BYTES );
a->infinity = 0;
return RIOT_SUCCESS;
}

void
RiotCrypt_ExportEccPub(
RIOT_ECC_PUBLIC *a, // IN: TODO
uint8_t *b, // OUT: TODO
uint32_t *s // OUT: TODO
const RIOT_ECC_PUBLIC *a, // IN: TODO
uint8_t *b, // OUT: TODO
uint32_t *s // OUT: TODO
)
{
*b++ = 0x04;
Expand All @@ -198,7 +225,6 @@ RiotCrypt_ExportEccPub(
}
}


RIOT_STATUS
RiotCrypt_Sign(
RIOT_ECC_SIGNATURE *sig, // OUT: TODO
Expand Down
62 changes: 38 additions & 24 deletions Emulator/RIoT/RIoTCrypt/RiotDerEnc.c → CyReP/RiotDerEnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@ Microsoft Copyright 2017
Confidential Information

*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h> // TODO: REMOVE THIS
#else
#include <arpa/inet.h>
#endif

#include "RiotDerEnc.h"
#include "RiotBase64.h"
#include <RiotTarget.h>
#include <RiotDerEnc.h>
#include <RiotBase64.h>

//
// This file contains basic DER-encoding routines that are sufficient to create
Expand All @@ -44,7 +34,7 @@ Confidential Information
// additions. CHECK_SPACE2 when larger objects are being added (and the length
// is known.)
#define CHECK_SPACE(_X) if((_X->Length-_X->Position)<32) {goto Error;}
#define CHECK_SPACE2(_X, _N) if(((_X->Length-_X->Position)+(_N))<32) {goto Error;}
#define CHECK_SPACE2(_X, _N) if((_X->Length-_X->Position)<(_N)) {goto Error;}

static int
GetIntEncodedNumBytes(
Expand Down Expand Up @@ -273,7 +263,7 @@ DERAddIntegerFromArray(
uint8_t *Val,
uint32_t NumBytes
)
// Input integer is assumed unsigned with most signficant byte first.
// Input integer is assumed unsigned with most significant byte first.
// A leading zero will be added if the most significant input bit is set.
// Leading zeros in the input number will be removed.
{
Expand All @@ -290,6 +280,11 @@ DERAddIntegerFromArray(
numLeadingZeros++;
}

// Handle zero case. We do not want index outside the buffer.
if (numLeadingZeros == NumBytes) {
numLeadingZeros--;
}

negative = Val[numLeadingZeros] >= 128;
Context->Buffer[Context->Position++] = 0x02;

Expand All @@ -314,7 +309,7 @@ DERAddInteger(
int Val
)
{
long valx = htonl(Val); // TODO: REMOVE USAGE
long valx = SWAP32(Val);
int res = DERAddIntegerFromArray(Context, (uint8_t*)&valx, 4);
return res;
}
Expand All @@ -331,7 +326,7 @@ DERAddShortExplicitInteger(
Context->Buffer[Context->Position++] = 0xA0;
Context->Buffer[Context->Position++] = 3;

valx = htonl(Val);
valx = SWAP32(Val);
return (DERAddIntegerFromArray(Context, (uint8_t*)&valx, 4));
Error:
return -1;
Expand Down Expand Up @@ -377,6 +372,25 @@ DERAddBitString(
return -1;
}

int
DERAddSequenceOctets(
DERBuilderContext *Context,
uint8_t Num,
uint8_t *OctetString,
uint32_t OctetStringLen
)
{
CHECK_SPACE2(Context, OctetStringLen);
Context->Buffer[Context->Position++] = 0x80 + Num;
EncodeInt(Context->Buffer + Context->Position, OctetStringLen);
Context->Position += GetIntEncodedNumBytes(OctetStringLen);
memcpy(Context->Buffer + Context->Position, OctetString, OctetStringLen);
Context->Position += OctetStringLen;
return 0;
Error:
return -1;
}

int
DERAddOctetString(
DERBuilderContext *Context,
Expand All @@ -395,7 +409,6 @@ DERAddOctetString(
return -1;
}


int
DERStartSequenceOrSet(
DERBuilderContext *Context,
Expand Down Expand Up @@ -432,6 +445,7 @@ DERStartExplicit(
Error:
return -1;
}

int
DERStartEnvelopingOctetString(
DERBuilderContext *Context
Expand Down Expand Up @@ -548,11 +562,11 @@ typedef struct
} PEMHeadersFooters;

// We only have a small subset of potential PEM encodings
const PEMHeadersFooters PEMhf[LAST_CERT_TYPE] = {
{28, 26, "-----BEGIN CERTIFICATE-----\n", "-----END CERTIFICATE-----\n"},
{27, 25, "-----BEGIN PUBLIC KEY-----\n", "-----END PUBLIC KEY-----\n\0"},
{31, 29, "-----BEGIN EC PRIVATE KEY-----\n", "-----END EC PRIVATE KEY-----\n"},
{36, 34, "-----BEGIN CERTIFICATE REQUEST-----\n", "-----END CERTIFICATE REQUEST-----\n"}
const PEMHeadersFooters PEMhf[R_LAST_CERT_TYPE] = {
{29, 27, "-----BEGIN CERTIFICATE-----\r\n", "-----END CERTIFICATE-----\r\n"},
{28, 26, "-----BEGIN PUBLIC KEY-----\r\n", "-----END PUBLIC KEY-----\r\n"},
{32, 30, "-----BEGIN EC PRIVATE KEY-----\r\n", "-----END EC PRIVATE KEY-----\r\n"},
{37, 35, "-----BEGIN CERTIFICATE REQUEST-----\r\n", "-----END CERTIFICATE REQUEST-----\r\n"}
};

int
Expand All @@ -568,7 +582,7 @@ DERtoPEM(
uint32_t b64Len, reqLen;

// Parameter validation
if (!(Context) || !(Type < LAST_CERT_TYPE) || !(PEM)) {
if (!(Context) || !(Type < R_LAST_CERT_TYPE) || !(PEM)) {
return -1;
}

Expand Down
Loading