Browse Source

better ASN.1

doc_update_sequoia
Volker Birk 6 years ago
parent
commit
24d3737328
5 changed files with 88 additions and 53 deletions
  1. +2
    -2
      asn.1/Makefile
  2. +19
    -14
      asn.1/devicegroup.asn1
  3. +22
    -12
      asn.1/pEp.asn1
  4. +43
    -24
      src/pEpEngine.c
  5. +2
    -1
      src/pEp_internal.h

+ 2
- 2
asn.1/Makefile View File

@ -1,11 +1,11 @@
include ../Makefile.conf
all: Message.c Message.h
all: Message.c
%.o: %.c %.h
$(CC) $(CFLAGS) -I$(ASN1C_INCLUDE) -c $< -o $@
Message.c Message.h: devicegroup.asn1
Message.c: devicegroup.asn1
$(ASN1C) -fcompound-names -pdu=PEP.Message pEp.asn1 $<
.PHONY: clean


+ 19
- 14
asn.1/devicegroup.asn1 View File

@ -1,25 +1,30 @@
DEVICEGROUP DEFINITIONS AUTOMATIC TAGS ::=
DEVICEGROUP
DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
BEGIN
Beacon ::= SEQUENCE {
header PEP.Header,
me PEP.Identity
IMPORTS Identity, KeyList, Header FROM PEP;
Beacon ::= [APPLICATION 1] SEQUENCE {
header Header,
me Identity
}
HandshakeRequest ::= SEQUENCE {
header PEP.Header,
you PEP.Identity,
me PEP.Identity
HandshakeRequest ::= [APPLICATION 2] SEQUENCE {
header Header,
you Identity,
me Identity
}
OwnKeys ::= SEQUENCE {
header PEP.Header,
you PEP.Identity,
me PEP.Identity,
keylist PEP.Stringlist
OwnKeys ::= [APPLICATION 3] SEQUENCE {
header Header,
you Identity,
me Identity,
keylist KeyList
}
Message ::= CHOICE {
SyncMessage ::= CHOICE {
beacon Beacon,
handshakeRequest HandshakeRequest,
ownKeys OwnKeys


+ 22
- 12
asn.1/pEp.asn1 View File

@ -1,26 +1,36 @@
PEP DEFINITIONS ::=
PEP
DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
BEGIN
EXPORTS Identity, KeyList, Header;
major-version INTEGER ::= 1
minor-version INTEGER ::= 0
ISO936-1 ::= PrintableString(FROM ("a".."z")) (SIZE(2))
Hex ::= PrintableString(FROM ("A".."F") | FROM ("0".."9"))
Hash ::= Hex(SIZE(50..128)) -- SHA1 to SHA512 in hex
Identity ::= SEQUENCE {
address UTF8String,
fpr UTF8String,
user-id UTF8String,
username UTF8String,
comm-type INTEGER (0..255),
lang PrintableString
address UTF8String (SIZE(1..1024)) OPTIONAL,
fpr Hash,
user-id UTF8String (SIZE(1..1024)) OPTIONAL,
username UTF8String (SIZE(1..1024)) OPTIONAL,
comm-type INTEGER (0..255) OPTIONAL,
lang ISO936-1 DEFAULT "en"
}
Stringlist ::= SEQUENCE OF UTF8String
KeyList ::= SEQUENCE OF Hash
Version ::= SEQUENCE {
major INTEGER (0..255),
minor INTEGER (0..255)
major INTEGER (0..255) DEFAULT major-version,
minor INTEGER (0..255) DEFAULT minor-version
}
Header ::= SEQUENCE {
protocol INTEGER (0..65535),
version Version,
message INTEGER (0..65535),
sequence INTEGER
}


+ 43
- 24
src/pEpEngine.c View File

@ -35,7 +35,8 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
static const char *sql_own_key_is_listed;
static const char *sql_own_key_retrieve;
static const char *sql_sequence_value;
static const char *sql_sequence_value1;
static const char *sql_sequence_value2;
bool in_first = false;
@ -264,11 +265,11 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
sql_own_key_retrieve = "select * from own_keys ;";
sql_sequence_value = "insert or replace into sequences (name, value) "
"values (?1, "
"(select coalesce((select value + 1 from sequences "
"where name = ?1), 1 ))) ; "
"select value from sequences where name = ?1 ;";
sql_sequence_value1 = "insert or replace into sequences (name, value) "
"values (?1, "
"(select coalesce((select value + 1 from sequences "
"where name = ?1), 1 ))) ; ";
sql_sequence_value2 = "select value from sequences where name = ?1 ;";
}
int_result = sqlite3_prepare_v2(_session->db, sql_log, (int)strlen(sql_log),
@ -344,17 +345,27 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
// Own keys
int_result = sqlite3_prepare_v2(_session->db, sql_own_key_add,
(int)strlen(sql_own_key_add), &_session->own_key_add, NULL);
(int)strlen(sql_own_key_add), &_session->own_key_add, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_own_key_is_listed,
(int)strlen(sql_own_key_is_listed), &_session->own_key_is_listed, NULL);
(int)strlen(sql_own_key_is_listed), &_session->own_key_is_listed, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_own_key_retrieve,
(int)strlen(sql_own_key_retrieve), &_session->own_key_retrieve, NULL);
(int)strlen(sql_own_key_retrieve), &_session->own_key_retrieve, NULL);
assert(int_result == SQLITE_OK);
// Sequence
int_result = sqlite3_prepare_v2(_session->db, sql_sequence_value1,
(int)strlen(sql_sequence_value1), &_session->sequence_value1, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_sequence_value2,
(int)strlen(sql_sequence_value2), &_session->sequence_value2, NULL);
assert(int_result == SQLITE_OK);
status = init_cryptotech(_session, in_first);
if (status != PEP_STATUS_OK)
goto pep_error;
@ -1432,22 +1443,30 @@ DYNAMIC_API PEP_STATUS sequence_value(
*value = 0;
sqlite3_reset(session->sequence_value);
sqlite3_bind_text(session->sequence_value, 1, name, -1, SQLITE_STATIC);
result = sqlite3_step(session->sequence_value);
switch (result) {
case SQLITE_ROW: {
int64_t _value = (int64_t)
sqlite3_column_int64(session->sequence_value, 0);
*value = _value;
break;
sqlite3_reset(session->sequence_value1);
sqlite3_bind_text(session->sequence_value1, 1, name, -1, SQLITE_STATIC);
result = sqlite3_step(session->sequence_value1);
assert(result == SQLITE_DONE);
sqlite3_reset(session->sequence_value1);
if (result != SQLITE_DONE) {
status = PEP_UNKNOWN_ERROR;
}
else {
sqlite3_reset(session->sequence_value2);
sqlite3_bind_text(session->sequence_value2, 1, name, -1, SQLITE_STATIC);
result = sqlite3_step(session->sequence_value2);
switch (result) {
case SQLITE_ROW: {
int64_t _value = (int64_t)
sqlite3_column_int64(session->sequence_value2, 0);
*value = _value;
break;
}
default:
status = PEP_UNKNOWN_ERROR;
}
default:
status = PEP_CANNOT_FIND_IDENTITY;
sqlite3_reset(session->sequence_value2);
}
sqlite3_reset(session->sequence_value);
return status;
}


+ 2
- 1
src/pEp_internal.h View File

@ -113,7 +113,8 @@ typedef struct _pEpSession {
sqlite3_stmt *own_key_retrieve;
// sequence value
sqlite3_stmt *sequence_value;
sqlite3_stmt *sequence_value1;
sqlite3_stmt *sequence_value2;
// callbacks
examine_identity_t examine_identity;


Loading…
Cancel
Save