typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize);
/**
- * Function pointer for getting peer's public key, own public and private keys and token
- * for raw public key generation.
+ * Function pointer for getting master key for raw public key OTM.
+ * Callback is expected to set *rpkMasterKey pointer to binary data buffer
+ * containing the key. Master key lenght must not exceed OXM_RPK_MASTER_KEY_MAX_SIZE.
*/
-typedef void (*GetRPKMasterKeyCallback)(char *rpkMasterKey, size_t *rpkMasterKeyLen);
+typedef void (*GetRPKMasterKeyCallback)(char **rpkMasterKey, size_t *rpkMasterKeyLen);
/**
* Function pointer to close the displied PIN.
void SetInputPinCB(InputPinCallback pinCB);
/**
- * Function to setting RPK key callback from user.
- *
- * @param rpkCB implementation of RPK parameters callback.
- */
-void SetGetRPKMasterKeyCB(GetRPKMasterKeyCallback rpkCB);
-
-/**
* Function to set the close PIN callback
* This callback will be invoked when PIN based OTM is finished.
*
OCStackResult GetMasterRPKCallback(OTMContext_t *otmCtx);
/**
+ * Function to setting RPK key callback from user.
+ *
+ * @param rpkCB implementation of RPK parameters callback.
+ */
+OCStackResult SetRPKMasterKeyCB(GetRPKMasterKeyCallback rpkCB);
+
+/**
+ * Function to unset the RPK master key callback.
+ * NOTE : Do not call this function while RPK based ownership transfer.
+ */
+OCStackResult UnsetRPKMasterKeyCB();
+
+/**
* Callback implemenration to establish a secure channel with PSK cipher suite.
*
* @param otmCtx Context of OTM, It includes current device information.
#include "srmutility.h"
#include "pmtypes.h"
#include "oxmverifycommon.h"
+#include "oxmrawpublickey.h"
#include "pkix_interface.h"
#include "hw_emul/hw_interface.h"
#include "mbedtls/x509_crt.h"
}
}
-static void InputRPKMasterKeyCB(uint8_t *rpkMasterKey, int *rpkMasterKeyLen)
+static char rpk[32] = {
+ 0xB2, 0xA2, 0x0D, 0xC0, 0xCB, 0x3C, 0xA0, 0x27,
+ 0x45, 0x00, 0x73, 0xBD, 0x02, 0xF5, 0x84, 0x4B,
+ 0x0C, 0x1C, 0xD6, 0x6A, 0xD3, 0x9E, 0x3F, 0x64,
+ 0x95, 0x6B, 0xB8, 0xCA, 0x58, 0xBC, 0xBE, 0xBE
+};
+
+static void InputRPKMasterKeyCB(char **rpkMasterKey, size_t *rpkMasterKeyLen)
{
if(!rpkMasterKey || !rpkMasterKeyLen)
{
return;
}
- uint8_t rpk[32] = {
- 0xfd, 0xb5, 0x48, 0xec, 0x9c, 0x16, 0xc9, 0x72,
- 0xc6, 0xee, 0xaf, 0x42, 0x64, 0x0d, 0xe5, 0xb6,
- 0x44, 0x78, 0x84, 0x9e, 0xdd, 0x5c, 0x1d, 0x31,
- 0xcf, 0xd0, 0xf2, 0xe8, 0xb1, 0xa4, 0xad, 0x0f
- };
-
- memcpy(rpkMasterKey, rpk, 32);
+ *rpkMasterKey = rpk;
*rpkMasterKeyLen = 32;
}
}
SetInputPinCB(inputPinCB);
- SetInputRPKMasterKeyCB(InputRPKMasterKeyCB);
+ SetRPKMasterKeyCB(InputRPKMasterKeyCB);
return 0;
}
static GetRPKMasterKeyCallback gGetRPKMasterKeyCallback = NULL;
-void SetInputRPKMasterKeyCB(GetRPKMasterKeyCallback rpkCB)
+OCStackResult SetRPKMasterKeyCB(GetRPKMasterKeyCallback rpkCB)
{
if(NULL == rpkCB)
{
OIC_LOG(ERROR, TAG, "Failed to set callback for rpk.");
- return;
+ return OC_STACK_INVALID_PARAM;
}
gGetRPKMasterKeyCallback = rpkCB;
+
+ return OC_STACK_OK;
}
-void UnsetRPKMasterKeyCB()
+OCStackResult UnsetRPKMasterKeyCB()
{
gGetRPKMasterKeyCallback = NULL;
+
+ return OC_STACK_OK;
}
OCStackResult CreateRPKBasedSelectOxmPayload(OTMContext_t* otmCtx, uint8_t **payload, size_t *size)
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size, true);
}
-OCStackResult GetMasterRPK(char* master, size_t* master_len)
+OCStackResult GetMasterRPK()
{
- if(!master || !master_len)
- {
- OIC_LOG(ERROR, TAG, "RPK buffer is NULL");
- return OC_STACK_INVALID_PARAM;
- }
-
- OIC_LOG(DEBUG, TAG, "Invoking gGetRPKMasterKeyCallback");
- if(gGetRPKMasterKeyCallback)
+ if (gGetRPKMasterKeyCallback)
{
- gGetRPKMasterKeyCallback(g_RPKOxmData.rpkData, &g_RPKOxmData.rpkSize);
- if (g_RPKOxmData.rpkSize > OXM_RPK_MASTER_KEY_MAX_SIZE)
+ OIC_LOG(DEBUG, TAG, "Invoking gGetRPKMasterKeyCallback");
+ char *rpkData = NULL;
+ size_t rpkSize = 0;
+ gGetRPKMasterKeyCallback(&rpkData, &rpkSize);
+ if (!rpkData)
+ {
+ OIC_LOG(ERROR, TAG, "RPK is NULL");
+ return OC_STACK_ERROR;
+ }
+ if (rpkSize > OXM_RPK_MASTER_KEY_MAX_SIZE)
{
- OIC_LOG(ERROR, TAG, "Buffer overflow: RPK master key must not exceed OXM_RPK_MASTER_KEY_MAX_SIZE");
+ OIC_LOG(ERROR, TAG, "RPK master key must not exceed OXM_RPK_MASTER_KEY_MAX_SIZE");
return OC_STACK_ERROR;
}
+ g_RPKOxmData.rpkSize = rpkSize;
+ memcpy(g_RPKOxmData.rpkData, rpkData, g_RPKOxmData.rpkSize);
}
else
{
OIC_LOG(ERROR, TAG, "Invoke RPK callback failed!");
- OIC_LOG(ERROR, TAG, "Callback for input RPK should be registered to use Random RPK based OxM.");
+ OIC_LOG(ERROR, TAG, "Callback for input RPK master key should be registered to use RPK based OxM.");
return OC_STACK_ERROR;
}
return OC_STACK_INVALID_PARAM;
}
- uint8_t rpkData[OXM_RPK_MASTER_KEY_MAX_SIZE + 1] = {0};
- size_t rpkLen = 0;
OCStackResult res = OC_STACK_ERROR;
- res = GetMasterRPK((char*)rpkData, &rpkLen);
+ res = GetMasterRPK();
if (OC_STACK_OK != res)
{
gClosePinDispalyCallback = closeCB;
}
-
void UnsetInputPinCB()
{
gInputPinCallback = NULL;
int DerivePSKUsingPIN(uint8_t* result)
{
- int dtlsRes = DeriveCryptoKeyFromPassword(
- (const unsigned char *)g_PinOxmData.pinData,
+ int dtlsRes = DeriveCryptoKeyFromPassword((const unsigned char *)g_PinOxmData.pinData,
g_PinOxmData.pinSize,
g_PinOxmData.newDevice.id,
UUID_LENGTH, PBKDF_ITERATIONS,