Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong SCS code sent by osdp_pd? #7

Closed
z8a opened this issue May 27, 2020 · 2 comments
Closed

Wrong SCS code sent by osdp_pd? #7

z8a opened this issue May 27, 2020 · 2 comments
Labels
Bug Something isn't working

Comments

@z8a
Copy link

z8a commented May 27, 2020

I'm using OSDP.Net library to check your library and I had problems with Secure Channel.
Changing osdp_pd.c with:

diff --git a/src/osdp_pd.c b/src/osdp_pd.c
index 5e5b997..02c63d7 100644
--- a/src/osdp_pd.c
+++ b/src/osdp_pd.c
@@ -330,7 +330,7 @@ int pd_build_reply(struct osdp_pd *p, struct osdp_data *reply, uint8_t * pkt)
 
 	if (smb && (smb[1] > SCS_14) && isset_flag(p, PD_FLAG_SC_ACTIVE)) {
 		smb[0] = 2;
-		smb[1] = (len > 1) ? SCS_17 : SCS_15;
+		smb[1] = (len > 1) ? SCS_18 : SCS_16;
 	}
 
 	if (len == 0) {

it works.
Is it correct?

@sidcha
Copy link
Member

sidcha commented May 27, 2020

Hi @z8a, that is indeed a bug. Thanks for reporting it. Since you did the work of finding it, do you want to raise a PR for this?

If you don't want to, let me know and I will make this commit for you.

@sidcha
Copy link
Member

sidcha commented May 27, 2020

A bit of background on how this bug managed to slip by all the testing (for my own reference). phy_decode_packet() was written to be reused between CP and PD so it was doing a more relaxed check at two places that allowed for this to happen.

Relaxed check on SCS_15 at osdp_phy.c line 310

	if (isset_flag(p, PD_FLAG_SC_ACTIVE) &&
		pkt->control & PKT_CONTROL_SCB &&
		pkt->data[1] >= SCS_15)
	{

Relaxed check on SCS_17 or SCS_18 at osdp_phy.c line 325

	if (pkt->data[1] == SCS_17 || pkt->data[1] == SCS_18) {

TODO: must fix these checks so we can catch faulty PDs.

@sidcha sidcha closed this as completed in 2f4f660 May 27, 2020
@sidcha sidcha added the Bug Something isn't working label May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants