oc_csr.c 1.46 KB
Newer Older
1
/*
Kishen Maloor's avatar
Kishen Maloor committed
2
// Copyright (c) 2018-2019 Intel Corporation
3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

17
#ifdef OC_SECURITY
18 19 20 21 22 23 24 25
#ifdef OC_PKI

#include "oc_csr.h"
#include "oc_api.h"
#include "oc_certs.h"
#include "oc_core_res.h"

void
George Nash's avatar
George Nash committed
26
get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
27
{
George Nash's avatar
George Nash committed
28
  (void)iface_mask;
29 30 31 32
  (void)data;

  size_t device = request->resource->device;

33
  unsigned char csr[4096];
34

35 36
  int ret = oc_certs_generate_csr(device, csr, OC_PDU_SIZE);
  if (ret != 0) {
37 38 39 40 41 42
    oc_send_response(request, OC_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }

  oc_rep_start_root_object();
  oc_process_baseline_interface(
Kishen Maloor's avatar
Kishen Maloor committed
43
    oc_core_get_resource_by_index(OCF_SEC_CSR, device));
44 45
  oc_rep_set_text_string(root, csr, (const char *)csr);
  oc_rep_set_text_string(root, encoding, "oic.sec.encoding.pem");
46 47 48 49 50 51 52 53
  oc_rep_end_root_object();

  oc_send_response(request, OC_STATUS_OK);
}

#else  /* OC_PKI */
typedef int dummy_declaration;
#endif /* !OC_PKI */
54
#endif /* OC_SECURITY */