public void OneTimeSetup() { RpkOneKey = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC, "P-256"); PskOneKey = new OneKey(); PskOneKey.Add(CoseKeyKeys.KeyType, GeneralValues.KeyType_Octet); PskOneKey.Add(CoseKeyParameterKeys.Octet_k, CBORObject.FromObject(new byte[10])); }
/// <summary> /// Given a first message in the Edhoc protocol, parse the message into pieces /// and fill in the data struture elements to continue processing. /// Throw an exception on failures. /// </summary> /// <param name="msgData"></param> /// <returns></returns> public static EdhocResponder ParseMessage1(byte[] msgData) { EdhocResponder edhoc = new EdhocResponder(); CBORObject msg = CBORObject.DecodeFromBytes(msgData); if (msg.Type != CBORType.Array) { throw new Exception("Invalid message"); } if (msg[0].AsInt32() == 1) { edhoc._fSymmetricSecret = false; } else if (msg[0].AsInt32() == 4) { edhoc._fSymmetricSecret = true; } else { throw new Exception("Invalid Message"); } // Fill in "their" data into the different arrays edhoc._Messages[0] = msgData; // message_1 edhoc._SessionId[1] = msg[1].GetByteString(); edhoc._Nonce[1] = msg[2].GetByteString(); edhoc._Keys[1] = new OneKey(msg[3]); // Their one time key edhoc._algKeyAgree = _SelectAlgorithm(msg[4], new CBORObject[] { AlgorithmValues.ECDH_SS_HKDF_256 }); edhoc._algAEAD = _SelectAlgorithm(msg[5], new CBORObject[] { AlgorithmValues.AES_CCM_64_64_128 }); if (!edhoc._fSymmetricSecret) { edhoc._algSign = _SelectAlgorithm(msg[6], new CBORObject[] { AlgorithmValues.ECDSA_256 }); } else { edhoc._kid[1] = msg[6]; } edhoc._Keys[0] = OneKey.GenerateKey(null, edhoc._Keys[1][CoseKeyKeys.KeyType], "X25519" /*edhoc._Keys[1][CoseKeyParameterKeys.EC_Curve].AsString()*/); #if true edhoc._SessionId[0] = new byte[2]; edhoc._random.NextBytes(edhoc._SessionId[0]); edhoc._Nonce[0] = new byte[8]; edhoc._random.NextBytes(edhoc._Nonce[0]); #else edhoc._SessionId[0] = Encoding.UTF8.GetBytes("Kid Svr"); edhoc._Nonce[0] = Encoding.UTF8.GetBytes("Server Nonce"); #endif MessageList.Add(new ListKey(edhoc._SessionId[0]), edhoc); return(edhoc); }
public void Setup() { keyOctet = new OneKey(); keyOctet.Add(CoseKeyKeys.KeyType, GeneralValues.KeyType_Octet); keyOctet.Add(CoseKeyParameterKeys.Octet_k, CBORObject.FromObject(octetKeyValue)); keyOctet.Add(CoseKeyKeys.KeyIdentifier, CBORObject.FromObject(octetKeyID)); keyEdDSA = OneKey.GenerateKey(null, GeneralValues.KeyType_EC, "P-256"); keyDSA = OneKey.GenerateKey(null, GeneralValues.KeyType_OKP, "Ed25519"); }
public static void OneTimeSetup(TestContext ctx) { #if SUPPORT_RPK RpkOneKey = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC, "P-256"); #endif PskOneKey = new OneKey(); PskOneKey.Add(CoseKeyKeys.KeyType, GeneralValues.KeyType_Octet); PskOneKey.Add(CoseKeyParameterKeys.Octet_k, CBORObject.FromObject(new byte[10])); }
private static void GenOscore(string[] cmds) { int count = int.Parse(cmds[1]); int keyType = int.Parse(cmds[2]); string algParams = cmds[3]; for (int i = 0; i < count; i++) { OneKey key = OneKey.GenerateKey(null, CBORObject.FromObject(keyType), algParams); Console.WriteLine("*** " + key.EncodeToCBORObject().ToString()); } }
private static void KdcJoin(string[] cmds) { if (cmds.Length != 3) { Console.WriteLine("Incorrect number of parameters"); return; } if ((Program._CurrentOscore == null) || (Program._CurrentOscore.UserData == null) || !(Program._CurrentOscore.UserData is GroupData)) { Console.WriteLine("Can't use the current OSCORE context"); return; } GroupData groupData = (GroupData)Program._CurrentOscore.UserData; OneKey signKey = OneKey.GenerateKey(null, GeneralValues.KeyType_OKP, "Ed25519"); byte[] signature = Signer.Sign(groupData.SignNonce, groupData.SignInfo[0], signKey); CBORObject join = CBORObject.NewMap(); CBORObject j2 = CBORObject.NewMap(); j2.Add(Confirmation.ConfirmationIds.COSE_Key, signKey.AsCBOR()); join.Add("type", 1); join.Add("client_cred", j2); join.Add("client_cred_verify", signature); Request request = new Request(Method.POST) { URI = new Uri(cmds[1]), Payload = @join.EncodeToBytes(), ContentType = MediaType.ApplicationCbor, OscoreContext = Program._CurrentOscore }; request.Send(); Response response = request.WaitForResponse(); if (response == null || response.StatusCode != StatusCode.Changed) { Console.WriteLine("Error in the response"); return; } CBORObject respBody = CBORObject.DecodeFromBytes(response.Payload); }
public void SetupServer() { psk = new OneKey(); psk.Add(CoseKeyKeys.KeyType, GeneralValues.KeyType_Octet); psk.Add(CoseKeyKeys.KeyIdentifier, CBORObject.FromObject(new byte[3] { 1, 2, 3 })); psk.Add(CoseKeyParameterKeys.Octet_k, CBORObject.FromObject(new byte[16] { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 })); _clientSignKey = OneKey.GenerateKey(null, GeneralValues.KeyType_EC, "P-256"); _clientSignKey.Add(CoseKeyKeys.Algorithm, AlgorithmValues.ECDSA_256); _clientSignKey.Add(CoseKeyKeys.KeyIdentifier, CBORObject.FromObject(new byte[] { 1, 101, 1 })); serverSignKey = OneKey.GenerateKey(null, GeneralValues.KeyType_EC, "P-256"); // serverSignKey = OneKey.GenerateKey(null, GeneralValues.KeyType_OKP, "Ed25519"); serverSignKey.Add(CoseKeyKeys.KeyIdentifier, CBORObject.FromObject(new byte[] { 101, 1, 101 })); // serverSignKey.Add(CoseKeyKeys.Algorithm, AlgorithmValues.EdDSA); serverSignKey.Add(CoseKeyKeys.Algorithm, AlgorithmValues.ECDSA_256); CreateServer(); }
/// <summary> /// Create an EDHOC context for a suplicant to generate messages from. /// </summary> /// <param name="contextKey">Either shared secret or signing to key to used to do identity proofing for</param> public EdhocInitiator(OneKey contextKey) { switch ((GeneralValuesInt)contextKey[CoseKeyKeys.KeyType].AsInt32()) { case GeneralValuesInt.KeyType_Octet: _fSymmetricSecret = true; _SharedSecret = contextKey; break; case GeneralValuesInt.KeyType_EC2: case GeneralValuesInt.KeyType_OKP: _fSymmetricSecret = false; if (!contextKey.ContainsName(CoseKeyParameterKeys.EC_D)) { throw new Exception("Need to supply a private key with the signing key"); } _SigningKey = contextKey; break; case GeneralValuesInt.KeyType_RSA: default: throw new Exception("Unknown key type for secret"); } // Save the items in the "Our" side of the arrays. _kid[0] = contextKey[CoseKeyKeys.KeyIdentifier]; #if true _SessionId[0] = new byte[2]; _random.NextBytes(_SessionId[0]); _Nonce[0] = new byte[8]; _random.NextBytes(_Nonce[0]); #else _SessionId[0] = Encoding.UTF8.GetBytes("kid client"); _Nonce[0] = Encoding.UTF8.GetBytes("Nonce Client"); #endif _Keys[0] = OneKey.GenerateKey(null, GeneralValues.KeyType_OKP, "X25519"); }
public void setUpClass() { cnKeyPrivate = OneKey.GenerateKey(null, GeneralValues.KeyType_EC, "P-256"); cnKeyPublic = cnKeyPrivate.PublicKey(); }
public static void ClassInit(TestContext e) { _clientSign1 = OneKey.GenerateKey(AlgorithmValues.EdDSA, GeneralValues.KeyType_OKP); _clientSign2 = OneKey.GenerateKey(AlgorithmValues.EdDSA, GeneralValues.KeyType_OKP); _serverSign1 = OneKey.GenerateKey(AlgorithmValues.EdDSA, GeneralValues.KeyType_OKP); }
static void Main(string[] args) { Options options = null; ParserResult <Options> optionResult = CommandLine.Parser.Default.ParseArguments <Options>(args) .WithParsed(o => { options = o; }) .WithNotParsed(o => { Console.WriteLine("Invalid command line"); Console.WriteLine(o.ToString()); Environment.Exit(1); }); Console.Title = options.Title; #if false { // Generate a pair of CWT messages signed by a third key. OneKey clientKey = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC); OneKey serverKey = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC); OneKey caKey = OneKey.GenerateKey(AlgorithmValues.ECDSA_256, GeneralValues.KeyType_EC); CWT clientCwt = new CWT(); clientCwt.Cnf = new Confirmation(clientKey.PublicKey()); clientCwt.SigningKey = caKey; CBORObject clientCwtCbor = clientCwt.EncodeToCBOR(); string clientCwtStr = clientCwtCbor.ToString(); byte[] clientCwtBytes = clientCwt.EncodeToBytes(); CWT serverCwt = new CWT() { Cnf = new Confirmation(serverKey), SigningKey = caKey }; CBORObject serverCwtCbor = serverCwt.EncodeToCBOR(); string serverCwtStr = serverCwtCbor.ToString(); byte[] serverCwtBytes = serverCwt.EncodeToBytes(); string caStr = caKey.EncodeToCBORObject().ToString(); } #endif LogManager.Instance = new FileLogManager(Console.Out); FillDispatchTable(dispatchTable); Oscore.Register(dispatchTable); #if DEV_VERSION Groups.FillDispatchTable(dispatchTable); #endif #if DO_ACE AceAuthz.AddCommands(dispatchTable); // Setup plain OAuth AceAuthzHandler = new AceAuthz(); #endif #if DO_RD ResourceDirectory.AddCommands(dispatchTable); #endif if (options.Script != null) { TextReader x = new StreamReader(options.Script); RunScript(x); x.Dispose(); } RunScript(Console.In); }