Exemple #1
0
int olsrd_mdp_sign(co_obj_t *self, co_obj_t **output, co_obj_t *params) {
  int msg_len = 0, ret = 0, sig_buf_len;
  unsigned char *msg = NULL, *sig_buf = NULL;
  
  /** skipping some error checking for performance reasons */
  
//   CHECK(IS_LIST(params) && co_list_length(params) == 2,"Invalid params");
  
  msg_len = co_obj_data((char**)&msg,co_list_element(params,1));
  sig_buf_len = SIGNATURE_BYTES + msg_len + 1;
  sig_buf = calloc(sig_buf_len,sizeof(unsigned char));
  
  CHECK(serval_create_signature((unsigned char*)_LIST_ELEMENT(params,0),
                     msg,
		     msg_len,
		     sig_buf,
		     sig_buf_len),"Failed to sign OLSRd packet");
  
  CMD_OUTPUT("sig",co_bin8_create((char*)(sig_buf+msg_len),SIGNATURE_BYTES,0));
  
  ret = 1;
error:
  if (sig_buf) free(sig_buf);
  return ret;
}
Exemple #2
0
int cmd_serval_sign(const char *sid_str, 
	 const size_t sid_len,
	 const unsigned char *msg,
	 const size_t msg_len,
	 char *sig_str_buf,
	 const size_t sig_str_size,
	 const char *keyring_path,
	 const size_t keyring_len) {
  
  int ret = 0;
  unsigned char signed_msg[msg_len + SIGNATURE_BYTES];
  keyring_file *_keyring = NULL;
  unsigned char *key = NULL;
  unsigned char packedSid[SID_SIZE] = {0};
  
  CHECK(sig_str_size >= 2*SIGNATURE_BYTES + 1,"Signature buffer too small");
  
  if (sid_str) {
    CHECK_ERR(sid_len == 2*SID_SIZE && str_is_subscriber_id(sid_str) == 1,"Invalid SID");
    stowSid(packedSid,0,sid_str);
  }
  
  if (keyring_path) {
    CHECK_ERR(serval_init_keyring(sid_str ? packedSid : NULL,
                     sid_str ? SID_SIZE : 0,
		     keyring_path,
		     keyring_len,
		     &_keyring,
		     &key,
		     NULL), "Failed to initialize Serval keyring");
  } else {
    CHECK_ERR(serval_extract_sas(&key,NULL,keyring,packedSid),"Failed to fetch SAS key");
  }
  
  CHECK_ERR(serval_create_signature(key, msg, msg_len, signed_msg, SIGNATURE_BYTES + msg_len),"Failed to create signature");
  
  strncpy(sig_str_buf,alloca_tohex(signed_msg + msg_len,SIGNATURE_BYTES),2*SIGNATURE_BYTES);
  sig_str_buf[2*SIGNATURE_BYTES] = '\0';

  ret = 1;
error:
  if (_keyring) keyring_free(_keyring);
  return ret;
}
Exemple #3
0
int
olsrd_mdp_sign(co_obj_t *self, co_obj_t **output, co_obj_t *params)
{
  int ret = 0;
  svl_crypto_ctx *ctx = svl_crypto_ctx_new();
  
  /** skipping some error checking for performance reasons */
  
//   CHECK(IS_LIST(params) && co_list_length(params) == 2, "Invalid params");
  
  ctx->msg_len = co_obj_data((char**)&ctx->msg, co_list_element(params, 1));
  
  memcpy(ctx->sas_private,_LIST_ELEMENT(params, 0),crypto_sign_SECRETKEYBYTES);
  
  CHECK(serval_create_signature(ctx), "Failed to sign OLSRd packet");
  
  CMD_OUTPUT("sig", co_bin8_create((char*)ctx->signature, SIGNATURE_BYTES, 0));
  
  ret = 1;
error:
  svl_crypto_ctx_free(ctx);
  return ret;
}
Exemple #4
0
int
cmd_serval_sign(svl_crypto_ctx *ctx)
{
  CHECK_ERR(ctx,"Invalid ctx");
  
  /* If a non-default keyring path is given, and/or no SID is set,
   * we need to initialize the keyring */
  if (ctx->keyring_path || !ctx->sid[0]) {
    CHECK_ERR(serval_init_keyring(ctx),
	      "Failed to initialize Serval keyring");
  } else {
    // or just use the default keyring
    ctx->keyring_file = keyring; // serval global
    CHECK_ERR(serval_extract_sas(ctx),
	      "Failed to fetch SAS keys");
  }
  
  CHECK_ERR(serval_create_signature(ctx),"Failed to create signature");
  
  return 1;
error:
  return 0;
}