Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-AMF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-AMF
Commits
047d11f9
Commit
047d11f9
authored
Mar 25, 2021
by
yangjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Authentication failed(Synch Failure)
parent
791e52be
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
37 deletions
+93
-37
src/amf-app/amf_n1.cpp
src/amf-app/amf_n1.cpp
+59
-24
src/amf-app/amf_n1.hpp
src/amf-app/amf_n1.hpp
+1
-1
src/nas/ies/UESecurityCapability.cpp
src/nas/ies/UESecurityCapability.cpp
+21
-0
src/ngap/ngapMsgs/InitialContextSetupRequest.cpp
src/ngap/ngapMsgs/InitialContextSetupRequest.cpp
+2
-2
src/ngap/ngapMsgs/InitialContextSetupResponse.cpp
src/ngap/ngapMsgs/InitialContextSetupResponse.cpp
+4
-4
src/ngap/ngapMsgs/InitialUEMessage.cpp
src/ngap/ngapMsgs/InitialUEMessage.cpp
+2
-2
src/ngap/ngapMsgs/PduSessionResourceSetupResponse.cpp
src/ngap/ngapMsgs/PduSessionResourceSetupResponse.cpp
+4
-4
No files found.
src/amf-app/amf_n1.cpp
View file @
047d11f9
...
...
@@ -86,6 +86,10 @@ extern int ncc;
Sha256
ctx
;
random_state_t
random_state
;
static
uint8_t
no_random_delta
=
0
;
static
std
::
map
<
std
::
string
,
std
::
string
>
rand_record
;
void
amf_n1_task
(
void
*
);
//------------------------------------------------------------------------------
...
...
@@ -1141,7 +1145,7 @@ bool amf_n1::auth_vectors_generator(std::shared_ptr<nas_context>& nc) {
return
true
;
}
//------------------------------------------------------------------------------
#define CURL_TIMEOUT_MS
1
00L
#define CURL_TIMEOUT_MS
3
00L
std
::
size_t
callback_ausf
(
const
char
*
in
,
std
::
size_t
size
,
std
::
size_t
num
,
std
::
string
*
out
)
{
...
...
@@ -1293,10 +1297,10 @@ bool amf_n1::authentication_vectors_from_ausf(
Logger
::
amf_n1
().
debug
(
"********* has auts *********"
);
char
*
auts_s
=
(
char
*
)
malloc
(
auts_len
*
2
+
1
);
char
*
rand_s
=
(
char
*
)
malloc
(
RAND_LENGTH
*
2
+
1
);
//
char* rand_s = (char*)malloc(RAND_LENGTH*2+1);
memset
(
auts_s
,
0
,
sizeof
(
auts_s
));
memset
(
rand_s
,
0
,
sizeof
(
rand_s
));
uint8_t
rand_value
[
RAND_LENGTH
];
//
memset(rand_s,0,sizeof(rand_s));
// uint8_t *rand_value;//
[RAND_LENGTH];
Logger
::
amf_n1
().
debug
(
"********* auts_len (%d) *********"
,
auts_len
);
...
...
@@ -1309,21 +1313,32 @@ bool amf_n1::authentication_vectors_from_ausf(
print_buffer
(
"amf_n1"
,
"********** ausf ***********"
,
auts_value
,
auts_len
);
Logger
::
amf_n1
().
info
(
"********** ausf_s (%s) ***********"
,
auts_s
);
generate_random
(
rand_value
,
RAND_LENGTH
);
for
(
int
i
=
0
;
i
<
RAND_LENGTH
;
i
++
)
//generate_random(rand_value, RAND_LENGTH);
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
iter
;
iter
=
rand_record
.
find
(
nc
.
get
()
->
imsi
);
if
(
iter
!=
rand_record
.
end
())
{
authenticationinfo_rand
=
iter
->
second
;
Logger
::
amf_n1
().
info
(
"********** rand_s (%s) ***********"
,
authenticationinfo_rand
.
c_str
());
}
else
{
sprintf
(
&
rand_s
[
i
*
2
],
"%02X"
,
rand_value
[
i
]
);
Logger
::
amf_n1
().
error
(
"********** There's no last rand ***********"
);
}
authenticationinfo_rand
=
rand_s
;
print_buffer
(
"amf_n1"
,
"********** rand ***********"
,
rand_value
,
RAND_LENGTH
);
Logger
::
amf_n1
().
info
(
"********** rand_s (%s) ***********"
,
rand_s
);
// rand_value = nc.get()->_5g_av[0].rand;
// for(int i=0;i<RAND_LENGTH;i++)
// {
// sprintf(&rand_s[i*2],"%02X",rand_value[i]);
// }
// authenticationinfo_rand = rand_s;
// print_buffer("amf_n1", "********** rand ***********", rand_value, RAND_LENGTH);
resynchronizationInfo
.
setAuts
(
authenticationinfo_auts
);
resynchronizationInfo
.
setRand
(
authenticationinfo_rand
);
authenticationinfo
.
setResynchronizationInfo
(
resynchronizationInfo
);
free
(
auts_s
);
free
(
rand_s
);
free
_wrapper
((
void
**
)
&
auts_s
);
// free_wrapper((void**) &
rand_s);
}
to_json
(
authenticationinfo_j
,
authenticationinfo
);
...
...
@@ -1339,6 +1354,8 @@ bool amf_n1::authentication_vectors_from_ausf(
unsigned
char
*
r5gauthdata_rand
=
format_string_as_hex
(
ueauthenticationctx
.
getR5gAuthData
().
getRand
());
memcpy
(
nc
.
get
()
->
_5g_av
[
0
].
rand
,
r5gauthdata_rand
,
16
);
rand_record
[
nc
.
get
()
->
imsi
]
=
ueauthenticationctx
.
getR5gAuthData
().
getRand
();
print_buffer
(
"amf_n1"
,
"5G AV: rand"
,
nc
.
get
()
->
_5g_av
[
0
].
rand
,
16
);
free_wrapper
((
void
**
)
&
r5gauthdata_rand
);
...
...
@@ -1371,7 +1388,7 @@ bool amf_n1::authentication_vectors_from_ausf(
}
bool
amf_n1
::
_5g_aka_confirmation_from_ausf
(
std
::
shared_ptr
<
nas_context
>&
nc
,
std
::
string
&
resStar
)
{
std
::
shared_ptr
<
nas_context
>&
nc
,
bstring
resStar
)
{
Logger
::
amf_n1
().
debug
(
"_5g_aka_confirmation_from_ausf"
);
std
::
string
remoteUri
=
nc
.
get
()
->
Href
;
...
...
@@ -1379,7 +1396,22 @@ bool amf_n1::_5g_aka_confirmation_from_ausf(
std
::
string
Response
;
std
::
string
resStar_string
;
convert_string_2_hex
(
resStar
,
resStar_string
);
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
iter
;
iter
=
rand_record
.
find
(
nc
.
get
()
->
imsi
);
rand_record
.
erase
(
iter
);
//convert_string_2_hex(resStar, resStar_string);
uint8_t
resStar_len
=
blength
(
resStar
);
uint8_t
*
resStar_value
=
(
uint8_t
*
)
bdata
(
resStar
);
char
*
resStar_s
=
(
char
*
)
malloc
(
resStar_len
*
2
+
1
);
for
(
int
i
=
0
;
i
<
resStar_len
;
i
++
)
{
sprintf
(
&
resStar_s
[
i
*
2
],
"%02X"
,
resStar_value
[
i
]);
}
resStar_string
=
resStar_s
;
print_buffer
(
"amf_n1"
,
"********** resStar ***********"
,
resStar_value
,
resStar_len
);
Logger
::
amf_n1
().
info
(
"********** resStar_s (%s) ***********"
,
resStar_s
);
nlohmann
::
json
confirmationdata_j
;
ConfirmationData
confirmationdata
;
...
...
@@ -1388,9 +1420,11 @@ bool amf_n1::_5g_aka_confirmation_from_ausf(
to_json
(
confirmationdata_j
,
confirmationdata
);
msgBody
=
confirmationdata_j
.
dump
();
curl_http_client
(
remoteUri
,
"PUT"
,
msgBody
,
Response
);
free_wrapper
((
void
**
)
&
resStar_s
);
Logger
::
amf_n1
().
info
(
"Get Json content from AUSF response: %s"
,
Response
.
c_str
());
try
{
ConfirmationDataResponse
confirmationdataresponse
;
nlohmann
::
json
::
parse
(
Response
.
c_str
()).
get_to
(
confirmationdataresponse
);
...
...
@@ -1555,13 +1589,14 @@ void amf_n1::generate_random(uint8_t* random_p, ssize_t length) {
mpz_urandomb
(
random_nb
,
random_state
.
state
,
8
*
length
);
pthread_mutex_unlock
(
&
random_state
.
lock
);
mpz_export
(
random_p
,
NULL
,
1
,
length
,
0
,
0
,
random_nb
);
// int r = 0, mask = 0, shift;
// for (int i = 0; i < length; i++) {
// if ((i % sizeof(i)) == 0) r = rand();
// shift = 8 * (i % sizeof(i));
// mask = 0xFF << shift;
// random_p[i] = (r & mask) >> shift;
// }
int
r
=
0
,
mask
=
0
,
shift
;
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
if
((
i
%
sizeof
(
i
))
==
0
)
r
=
rand
();
shift
=
8
*
(
i
%
sizeof
(
i
));
mask
=
0xFF
<<
shift
;
random_p
[
i
]
=
(
r
&
mask
)
>>
shift
;
}
Logger
::
amf_n1
().
debug
(
"*************** generate rand function %x ***************"
,
r
);
}
else
{
Logger
::
amf_n1
().
error
(
"AMF config random -> false"
);
pthread_mutex_lock
(
&
random_state
.
lock
);
...
...
@@ -1778,8 +1813,8 @@ void amf_n1::authentication_response_handle(uint32_t ran_ue_ngap_id,
}
else
{
if
(
amf_cfg
.
is_Nausf
)
{
std
::
string
data
=
bdata
(
resStar
);
if
(
!
_5g_aka_confirmation_from_ausf
(
nc
,
data
))
//
std::string data = bdata(resStar);
if
(
!
_5g_aka_confirmation_from_ausf
(
nc
,
resStar
))
isAuthOk
=
false
;
}
else
...
...
src/amf-app/amf_n1.hpp
View file @
047d11f9
...
...
@@ -112,7 +112,7 @@ class amf_n1 {
std
::
string
&
Response
);
bool
authentication_vectors_from_ausf
(
std
::
shared_ptr
<
nas_context
>&
nc
);
bool
_5g_aka_confirmation_from_ausf
(
std
::
shared_ptr
<
nas_context
>&
nc
,
std
::
string
&
resStar
);
std
::
shared_ptr
<
nas_context
>&
nc
,
bstring
resStar
);
bool
authentication_vectors_generator_in_ausf
(
std
::
shared_ptr
<
nas_context
>&
nc
);
...
...
src/nas/ies/UESecurityCapability.cpp
View file @
047d11f9
...
...
@@ -87,6 +87,13 @@ int UESecurityCapability::encode2buffer(uint8_t* buf, int len) {
encoded_size
++
;
*
(
buf
+
encoded_size
)
=
_5g_IASel
;
encoded_size
++
;
// if(length == 4)
// {
// *(buf + encoded_size) = 0xf0;
// encoded_size++;
// *(buf + encoded_size) = 0xf0;
// encoded_size++;
// }
}
else
{
*
(
buf
+
encoded_size
)
=
length
-
2
;
encoded_size
++
;
...
...
@@ -94,6 +101,13 @@ int UESecurityCapability::encode2buffer(uint8_t* buf, int len) {
encoded_size
++
;
*
(
buf
+
encoded_size
)
=
_5g_IASel
;
encoded_size
++
;
// if(length == 4)
// {
// *(buf + encoded_size) = 0xf0;
// encoded_size++;
// *(buf + encoded_size) = 0xf0;
// encoded_size++;
// }
}
Logger
::
nas_mm
().
debug
(
"encoded UESecurityCapability (len %d)"
,
encoded_size
);
return
encoded_size
;
...
...
@@ -113,6 +127,13 @@ int UESecurityCapability::decodefrombuffer(
decoded_size
++
;
_5g_IASel
=
*
(
buf
+
decoded_size
);
decoded_size
++
;
if
(
length
==
4
)
{
decoded_size
++
;
decoded_size
++
;
}
Logger
::
nas_mm
().
debug
(
"UESecurityCapability EA 0x%d,IA 0x%d"
,
_5g_EASel
,
_5g_IASel
);
return
decoded_size
;
...
...
src/ngap/ngapMsgs/InitialContextSetupRequest.cpp
View file @
047d11f9
...
...
@@ -470,7 +470,7 @@ void InitialContextSetupRequestMsg::setNasPdu(uint8_t* nas, size_t sizeofnas) {
(
Ngap_InitialContextSetupRequestIEs_t
*
)
calloc
(
1
,
sizeof
(
Ngap_InitialContextSetupRequestIEs_t
));
ie
->
id
=
Ngap_ProtocolIE_ID_id_NAS_PDU
;
ie
->
criticality
=
Ngap_Criticality_
reject
;
ie
->
criticality
=
Ngap_Criticality_
ignore
;
ie
->
value
.
present
=
Ngap_InitialContextSetupRequestIEs__value_PR_NAS_PDU
;
int
ret
=
nasPdu
->
encode2octetstring
(
ie
->
value
.
choice
.
NAS_PDU
);
...
...
@@ -738,7 +738,7 @@ bool InitialContextSetupRequestMsg::decodefrompdu(
}
break
;
case
Ngap_ProtocolIE_ID_id_NAS_PDU
:
{
if
(
initialContextSetupRequestIEs
->
protocolIEs
.
list
.
array
[
i
]
->
criticality
==
Ngap_Criticality_
reject
&&
->
criticality
==
Ngap_Criticality_
ignore
&&
initialContextSetupRequestIEs
->
protocolIEs
.
list
.
array
[
i
]
->
value
.
present
==
Ngap_InitialContextSetupRequestIEs__value_PR_NAS_PDU
)
{
...
...
src/ngap/ngapMsgs/InitialContextSetupResponse.cpp
View file @
047d11f9
...
...
@@ -267,8 +267,8 @@ bool InitialContextSetupResponseMsg::decodefrompdu(
i
++
)
{
switch
(
initialContextSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
id
)
{
case
Ngap_ProtocolIE_ID_id_AMF_UE_NGAP_ID
:
{
if
(
i
nitialContextSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
criticality
==
Ngap_Criticality_ignore
&&
if
(
/*
nitialContextSetupResponseIEs->protocolIEs.list.array[i]
->criticality == Ngap_Criticality_ignore &&
*/
initialContextSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
value
.
present
==
Ngap_InitialContextSetupResponseIEs__value_PR_AMF_UE_NGAP_ID
)
{
...
...
@@ -285,8 +285,8 @@ bool InitialContextSetupResponseMsg::decodefrompdu(
}
}
break
;
case
Ngap_ProtocolIE_ID_id_RAN_UE_NGAP_ID
:
{
if
(
initialContextSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
criticality
==
Ngap_Criticality_ignore
&&
if
(
/*
initialContextSetupResponseIEs->protocolIEs.list.array[i]
->criticality == Ngap_Criticality_ignore &&
*/
initialContextSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
value
.
present
==
Ngap_InitialContextSetupResponseIEs__value_PR_RAN_UE_NGAP_ID
)
{
...
...
src/ngap/ngapMsgs/InitialUEMessage.cpp
View file @
047d11f9
...
...
@@ -294,8 +294,8 @@ bool InitialUEMessageMsg::decodefrompdu(Ngap_NGAP_PDU_t* ngap_msg_pdu) {
}
}
break
;
case
Ngap_ProtocolIE_ID_id_UserLocationInformation
:
{
if
(
initialUEMessageIEs
->
protocolIEs
.
list
.
array
[
i
]
->
criticality
==
Ngap_Criticality_reject
&&
if
(
/*
initialUEMessageIEs->protocolIEs.list.array[i]->criticality ==
Ngap_Criticality_reject &&
*/
initialUEMessageIEs
->
protocolIEs
.
list
.
array
[
i
]
->
value
.
present
==
Ngap_InitialUEMessage_IEs__value_PR_UserLocationInformation
)
{
userLocationInformation
=
new
UserLocationInformation
();
...
...
src/ngap/ngapMsgs/PduSessionResourceSetupResponse.cpp
View file @
047d11f9
...
...
@@ -273,8 +273,8 @@ bool PduSessionResourceSetupResponseMsg::decodefrompdu(
i
<
pduSessionResourceSetupResponseIEs
->
protocolIEs
.
list
.
count
;
i
++
)
{
switch
(
pduSessionResourceSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
id
)
{
case
Ngap_ProtocolIE_ID_id_AMF_UE_NGAP_ID
:
{
if
(
pduSessionResourceSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
criticality
==
Ngap_Criticality_ignore
&&
if
(
/*
pduSessionResourceSetupResponseIEs->protocolIEs.list.array[i]
->criticality == Ngap_Criticality_ignore &&
*/
pduSessionResourceSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
value
.
present
==
Ngap_PDUSessionResourceSetupResponseIEs__value_PR_AMF_UE_NGAP_ID
)
{
...
...
@@ -291,8 +291,8 @@ bool PduSessionResourceSetupResponseMsg::decodefrompdu(
}
}
break
;
case
Ngap_ProtocolIE_ID_id_RAN_UE_NGAP_ID
:
{
if
(
pduSessionResourceSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
criticality
==
Ngap_Criticality_ignore
&&
if
(
/*
pduSessionResourceSetupResponseIEs->protocolIEs.list.array[i]
->criticality == Ngap_Criticality_ignore &&
*/
pduSessionResourceSetupResponseIEs
->
protocolIEs
.
list
.
array
[
i
]
->
value
.
present
==
Ngap_PDUSessionResourceSetupResponseIEs__value_PR_RAN_UE_NGAP_ID
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment