Skip to content

Commit db95c5d

Browse files
authored
Merge branch 'develop' into RDKEMW-6767
2 parents 9a1bce1 + 953d8e8 commit db95c5d

8 files changed

Lines changed: 195 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,17 @@ if(ASSERT_ON_WRONG_THREAD)
200200
endif()
201201

202202
if(AUTH_ENABLED)
203-
if(EXISTS ${CMAKE_SYSROOT}/usr/lib/libctrlm-hal-certificate.so)
204-
add_compile_definitions(AUTH_ENABLED)
205-
add_compile_definitions(AUTH_ACCOUNT_ID)
206-
add_compile_definitions(AUTH_DEVICE_ID)
207-
add_compile_definitions(AUTH_PARTNER_ID)
208-
add_compile_definitions(AUTH_SAT_TOKEN)
209-
if(AUTH_ACTIVATION_STATUS)
210-
add_compile_definitions(AUTH_ACTIVATION_STATUS)
211-
endif()
212-
#By default disabled but can be enabled
213-
#add_compile_definitions(AUTH_EXPERIENCE)
214-
target_link_libraries(controlMgr ctrlm-hal-certificate)
215-
else()
216-
message(WARNING "ctrlm-hal-certificate library is not provided, disabling authentication")
217-
unset(AUTH_ENABLED)
203+
add_compile_definitions(AUTH_ENABLED)
204+
add_compile_definitions(AUTH_ACCOUNT_ID)
205+
add_compile_definitions(AUTH_DEVICE_ID)
206+
add_compile_definitions(AUTH_PARTNER_ID)
207+
add_compile_definitions(AUTH_SAT_TOKEN)
208+
if(AUTH_ACTIVATION_STATUS)
209+
add_compile_definitions(AUTH_ACTIVATION_STATUS)
218210
endif()
211+
#By default disabled but can be enabled
212+
#add_compile_definitions(AUTH_EXPERIENCE)
213+
target_link_libraries(controlMgr RdkCertSelector)
219214
endif()
220215

221216
if(BLE_ENABLED)

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ if(THUNDER)
215215
target_sources(controlMgr PRIVATE
216216
auth/ctrlm_auth.cpp
217217
auth/ctrlm_auth_thunder.cpp
218+
auth/ctrlm_auth_certificate.cpp
218219
auth/ctrlm_thunder_plugin_authservice.cpp
219220
)
220221
endif()
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* If not stated otherwise in this file or this component's license file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2015 RDK Management
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
#include <string.h>
20+
#include <sys/stat.h>
21+
#include <openssl/pkcs12.h>
22+
#include <openssl/pem.h>
23+
#include <openssl/evp.h>
24+
#include <errno.h>
25+
#include <dirent.h>
26+
#include "rdkcertselector.h"
27+
#include "ctrlm_auth_certificate.h"
28+
#include "ctrlm_utils.h"
29+
#include "ctrlm_log.h"
30+
31+
#define CERT_FILENAME_PREFIX "file://"
32+
33+
ctrlm_auth_certificate_t *ctrlm_auth_certificate_get() {
34+
return(new(ctrlm_auth_certificate_t));
35+
}
36+
37+
ctrlm_auth_certificate_t::ctrlm_auth_certificate_t() {
38+
39+
this->device_cert.type = CTRLM_VOICE_CERT_TYPE_NONE;
40+
this->ocsp_verify_stapling = false;
41+
this->ocsp_verify_ca = false;
42+
43+
char *cert_path = NULL;
44+
char *cert_password = NULL;
45+
rdkcertselector_h cert_selector = rdkcertselector_new( NULL, NULL, "MTLS" );
46+
47+
if(cert_selector == NULL){
48+
XLOGD_TELEMETRY("cert selector init failed");
49+
} else {
50+
rdkcertselectorStatus_t cert_status = rdkcertselector_getCert(cert_selector, &cert_path, &cert_password);
51+
52+
if(cert_status != certselectorOk) {
53+
XLOGD_TELEMETRY("cert selector retrieval failed");
54+
} else {
55+
if(cert_path == NULL || cert_password == NULL) {
56+
XLOGD_TELEMETRY("cert selector get failed");
57+
} else {
58+
59+
char *local_path = cert_path;
60+
if(strncmp(local_path, CERT_FILENAME_PREFIX, strlen(CERT_FILENAME_PREFIX)) == 0) {
61+
local_path += strlen(CERT_FILENAME_PREFIX);
62+
}
63+
if(!this->device_cert_p12_set(local_path, cert_password)) {
64+
XLOGD_TELEMETRY("unable to set device certificate <%s>", local_path);
65+
} else {
66+
struct stat file_info;
67+
// OCSP is a global setting that is enabled via RFC in systemd service ocsp-support
68+
if(stat("/tmp/.EnableOCSPStapling", &file_info) == 0) {
69+
XLOGD_TELEMETRY("OCSP verification enabled (stapling)");
70+
this->ocsp_verify_stapling = true;
71+
}
72+
if(stat("/tmp/.EnableOCSPCA", &file_info) == 0) {
73+
XLOGD_TELEMETRY("OCSP verification enabled (CA)");
74+
this->ocsp_verify_ca = true;
75+
}
76+
if(!this->ocsp_verify_stapling && !this->ocsp_verify_ca) {
77+
XLOGD_TELEMETRY("OCSP verification disabled");
78+
}
79+
}
80+
}
81+
}
82+
}
83+
84+
if(cert_selector != NULL) {
85+
rdkcertselector_free(&cert_selector);
86+
}
87+
}
88+
89+
ctrlm_auth_certificate_t::~ctrlm_auth_certificate_t() {
90+
if(this->device_cert.type == CTRLM_VOICE_CERT_TYPE_P12) {
91+
if(this->device_cert.cert.p12.certificate != NULL) {
92+
free((void *)this->device_cert.cert.p12.certificate);
93+
}
94+
if(this->device_cert.cert.p12.passphrase != NULL) {
95+
free((void *)this->device_cert.cert.p12.passphrase);
96+
}
97+
}
98+
}
99+
100+
bool ctrlm_auth_certificate_t::device_cert_get(ctrlm_voice_cert_t &device_cert, bool &ocsp_verify_stapling, bool &ocsp_verify_ca) {
101+
102+
device_cert = this->device_cert;
103+
ocsp_verify_stapling = this->ocsp_verify_stapling;
104+
ocsp_verify_ca = this->ocsp_verify_ca;
105+
return(true);
106+
}
107+
108+
bool ctrlm_auth_certificate_t::device_cert_p12_set(const char *certificate, const char *passphrase) {
109+
bool cert_valid = false;
110+
111+
// Extract the certificate, private key and additional certificates
112+
PKCS12 *p12_cert = NULL;
113+
EVP_PKEY *pkey = NULL;
114+
X509 *x509_cert = NULL;
115+
STACK_OF(X509) *additional_certs = NULL;
116+
117+
do {
118+
FILE *fp = fopen(certificate, "rb");
119+
if(fp == NULL) {
120+
XLOGD_ERROR("unable to open P12 certificate <%s>", certificate);
121+
break;
122+
}
123+
124+
d2i_PKCS12_fp(fp, &p12_cert);
125+
fclose(fp);
126+
fp = NULL;
127+
128+
if(p12_cert == NULL) {
129+
XLOGD_ERROR("unable to read P12 certificate <%s>", certificate);
130+
break;
131+
}
132+
133+
if(1 != PKCS12_parse(p12_cert, passphrase, &pkey, &x509_cert, &additional_certs)) {
134+
XLOGD_ERROR("unable to parse P12 certificate <%s>", certificate);
135+
break;
136+
}
137+
138+
this->device_cert.type = CTRLM_VOICE_CERT_TYPE_P12;
139+
this->device_cert.cert.p12.certificate = strdup(certificate);
140+
this->device_cert.cert.p12.passphrase = strdup(passphrase);
141+
142+
// Ensure the strings were duplicated
143+
if(this->device_cert.cert.p12.certificate == NULL || this->device_cert.cert.p12.passphrase == NULL) {
144+
this->device_cert.type = CTRLM_VOICE_CERT_TYPE_NONE;
145+
if(this->device_cert.cert.p12.certificate != NULL) {
146+
free((void *)this->device_cert.cert.p12.certificate);
147+
}
148+
if(this->device_cert.cert.p12.passphrase != NULL) {
149+
free((void *)this->device_cert.cert.p12.passphrase);
150+
}
151+
} else {
152+
cert_valid = true;
153+
}
154+
155+
} while(0);
156+
157+
if(p12_cert != NULL) {
158+
PKCS12_free(p12_cert);
159+
}
160+
if(pkey != NULL) {
161+
EVP_PKEY_free(pkey);
162+
}
163+
if(x509_cert != NULL) {
164+
X509_free(x509_cert);
165+
}
166+
if(additional_certs != NULL) {
167+
sk_X509_pop_free(additional_certs, X509_free);
168+
}
169+
170+
return(cert_valid);
171+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* limitations under the License.
1818
*/
1919

20-
#ifndef __CTRLM_HAL_CERTIFICATE_H__
21-
#define __CTRLM_HAL_CERTIFICATE_H__
20+
#ifndef __CTRLM_AUTH_CERTIFICATE_H__
21+
#define __CTRLM_AUTH_CERTIFICATE_H__
2222

2323
#include <stdio.h>
2424
#include <stdlib.h>
@@ -62,10 +62,10 @@ typedef struct {
6262
} cert;
6363
} ctrlm_voice_cert_t;
6464

65-
class ctrlm_hal_certificate_t {
65+
class ctrlm_auth_certificate_t {
6666
public:
67-
ctrlm_hal_certificate_t();
68-
virtual ~ctrlm_hal_certificate_t();
67+
ctrlm_auth_certificate_t();
68+
virtual ~ctrlm_auth_certificate_t();
6969

7070
virtual bool device_cert_get(ctrlm_voice_cert_t &device_cert, bool &ocsp_verify_stapling, bool &ocsp_verify_ca);
7171

@@ -77,6 +77,6 @@ class ctrlm_hal_certificate_t {
7777
bool ocsp_verify_ca;
7878
};
7979

80-
ctrlm_hal_certificate_t *ctrlm_hal_certificate_get();
80+
ctrlm_auth_certificate_t *ctrlm_auth_certificate_get();
8181

8282
#endif

src/ctrlm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "ctrlm_hal.h"
3030
#include "ctrlm_hal_rf4ce.h"
3131
#include "ctrlm_hal_ble.h"
32-
#include "ctrlm_hal_certificate.h"
3332
#include "ctrlm_hal_ip.h"
3433
#include "ctrlm_ipc.h"
3534
#include "ctrlm_ipc_rcu.h"

src/ctrlm_main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#endif
6363
#ifdef AUTH_ENABLED
6464
#include "ctrlm_auth.h"
65-
#include "ctrlm_hal_certificate.h"
65+
#include "ctrlm_auth_certificate.h"
6666
#endif
6767
#include "ctrlm_rfc.h"
6868
#include "ctrlm_telemetry.h"
@@ -278,7 +278,7 @@ typedef struct {
278278
ctrlm_cs_values_t cs_values;
279279
#ifdef AUTH_ENABLED
280280
ctrlm_auth_t *authservice;
281-
ctrlm_hal_certificate_t *hal_certificate;
281+
ctrlm_auth_certificate_t *auth_certificate;
282282
#endif
283283
#ifdef CTRLM_THUNDER
284284
Thunder::DeviceInfo::ctrlm_thunder_plugin_device_info_t *thunder_device_info;
@@ -694,14 +694,14 @@ int main(int argc, char *argv[]) {
694694

695695
#ifdef AUTH_ENABLED
696696
XLOGD_INFO("ctrlm_auth init");
697-
g_ctrlm.authservice = ctrlm_auth_service_create(g_ctrlm.server_url_authservice);
698-
g_ctrlm.hal_certificate = ctrlm_hal_certificate_get();
697+
g_ctrlm.authservice = ctrlm_auth_service_create(g_ctrlm.server_url_authservice);
698+
g_ctrlm.auth_certificate = ctrlm_auth_certificate_get();
699699

700700
ctrlm_voice_cert_t device_cert;
701701
bool ocsp_verify_stapling = false;
702702
bool ocsp_verify_ca = false;
703703

704-
if(!g_ctrlm.hal_certificate->device_cert_get(device_cert, ocsp_verify_stapling, ocsp_verify_ca)) {
704+
if(!g_ctrlm.auth_certificate->device_cert_get(device_cert, ocsp_verify_stapling, ocsp_verify_ca)) {
705705
XLOGD_ERROR("unable to get device certificate");
706706
} else {
707707
if(!g_ctrlm.voice_session->voice_stb_data_device_certificate_set(device_cert, ocsp_verify_stapling, ocsp_verify_ca)) {

src/ctrlm_utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ static const map<uint16_t, tuple<const char*, const char*>> ctrlm_linux_key_name
13171317
{KEY_F21, {"Guide", "Guide"}},
13181318
{KEY_EPG, {"Guide", "Guide"}},
13191319
{KEY_F22, {"Accessibility", "Accessibility"}},
1320+
{KEY_F23, {"AMC App", "AMC App"}},
13201321
{KEY_F8, {"Voice", "Voice"}},
13211322
{KEY_ESC, {"Dismiss", "Dismiss"}},
13221323
{KEY_F9, {"Quick Access Menu", "Quick Access Menu"}},

src/voice/ctrlm_voice_obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ctrlm_ipc_voice.h"
2929
#include "ctrlm.h"
3030
#include "ctrlm_auth.h"
31+
#include "ctrlm_auth_certificate.h"
3132
#include "jansson.h"
3233
#include "json_config.h"
3334
#include "xr_timestamp.h"

0 commit comments

Comments
 (0)