aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorNuno Goncalves <[email protected]>2019-06-15 18:30:43 +0200
committerNuno Goncalves <[email protected]>2019-10-14 15:59:38 +0200
commitbbad5e1eadff2f985fbc4b905eedb83017c8116e (patch)
treed01fd9e4137e5438f97a3062e19b1f251a200e20 /src/tests
parent63fa712b5ba091d281be178bcdc5dce592c92233 (diff)
Add roughtime protocol
Signed-off-by: Nuno Goncalves <[email protected]>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/data/misc/roughtime_nonce_from_blind.vec9
-rw-r--r--src/tests/data/misc/roughtime_request.vec7
-rw-r--r--src/tests/data/misc/roughtime_response.vec67
-rw-r--r--src/tests/test_roughtime.cpp264
4 files changed, 347 insertions, 0 deletions
diff --git a/src/tests/data/misc/roughtime_nonce_from_blind.vec b/src/tests/data/misc/roughtime_nonce_from_blind.vec
new file mode 100644
index 000000000..3705f30ae
--- /dev/null
+++ b/src/tests/data/misc/roughtime_nonce_from_blind.vec
@@ -0,0 +1,9 @@
+[Valid]
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E4458030878C605DE2F4234E53D659CC362EEEDC0CE19F25F0A115E51ED2EFB90B3C0474892929324EA4A262838CDAE5A4209512532B21DD0E05E2A00B7044DB9950E03000000040000000C000000524144494D494450524F4F5440420F00AC8139619F8205003504CBB433EF121955E1E7F3441C9EBFB213824480EA54890147638F3F6425A6DFA8A2FC3703628880D9255E6261BA642CC4BA35315787EC7DE079E7C752B97902000000400000005349470044454C45340B2E9950BF4ACDE29EFB068E7DA93F1B6EAB95E8C292C082C8FD3C362CB1A8F67A1A65E81416633EACDBB5775015384550D358FAFF6C43981BE9D1DE8C66010300000020000000280000005055424B4D494E544D415854B86B5758A08079BBFCE46D1DEC22D7AE855AD092CCF38FE1A783DCB0A3A3BD560000000000000000FFFFFFFFFFFFFFFF00000000
+Blind = D1659ADE0A96C925178B12D8E421FC476F11B2095AD5486668754BA7D134E83C9296DE312B63751FDA3D65B134CBCFD177F0397A68B301111CB538FC53304DD4
+Nonce = E2E1C752DDEDBD766DDB32E9598D9E97C34BFBC4C6C2D46E4470AC68BF00E3FC505A0EBDDF93ADCE5195A22D97F71F13F1EDB5569D89AE8CD0ABA16B4E0F1507
+
+[Invalid]
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E4458030878C605DE2F4234E53D659CC362EEEDC0CE19F25F0A115E51ED2EFB90B3C0474892929324EA4A262838CDAE5A4209512532B21DD0E05E2A00B7044DB9950E03000000040000000C000000524144494D494450524F4F5440420F00AC8139619F8205003504CBB433EF121955E1E7F3441C9EBFB213824480EA54890147638F3F6425A6DFA8A2FC3703628880D9255E6261BA642CC4BA35315787EC7DE079E7C752B97902000000400000005349470044454C45340B2E9950BF4ACDE29EFB068E7DA93F1B6EAB95E8C292C082C8FD3C362CB1A8F67A1A65E81416633EACDBB5775015384550D358FAFF6C43981BE9D1DE8C66010300000020000000280000005055424B4D494E544D415854B86B5758A08079BBFCE46D1DEC22D7AE855AD092CCF38FE1A783DCB0A3A3BD560000000000000000FFFFFFFFFFFFFFFF00000000
+Blind = D2659ADE0A96C925178B12D8E421FC476F11B2095AD5486668754BA7D134E83C9296DE312B63751FDA3D65B134CBCFD177F0397A68B301111CB538FC53304DD4
+Nonce = E2E1C752DDEDBD766DDB32E9598D9E97C34BFBC4C6C2D46E4470AC68BF00E3FC505A0EBDDF93ADCE5195A22D97F71F13F1EDB5569D89AE8CD0ABA16B4E0F1507
diff --git a/src/tests/data/misc/roughtime_request.vec b/src/tests/data/misc/roughtime_request.vec
new file mode 100644
index 000000000..637346097
--- /dev/null
+++ b/src/tests/data/misc/roughtime_request.vec
@@ -0,0 +1,7 @@
+[Valid]
+Nonce = 83ED2ACE13F29CF02EFB939A6EC79A4BBB7BE7D9E5854FD083FDB01E64BBDBDFEDA23A9FB9EA4BD02F469FFAD10CDD58D049D44E1EB74FA5697A098674546D6D
+Request = 02000000400000004E4F4E43504144FF83ED2ACE13F29CF02EFB939A6EC79A4BBB7BE7D9E5854FD083FDB01E64BBDBDFEDA23A9FB9EA4BD02F469FFAD10CDD58D049D44E1EB74FA5697A098674546D6D0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+
+[Invalid]
+Nonce = 83ED2ACE13F29CF02EFB939A6EC79A4BBB7BE7D9E5854FD083FDB01E64BBDBDFEDA23A9FB9EA4BD02F469FFAD10CDD58D049D44E1EB74FA5697A098674546D6D
+Request = 03000000400000004E4F4E43504144FF83ED2ACE13F29CF02EFB939A6EC79A4BBB7BE7D9E5854FD083FDB01E64BBDBDFEDA23A9FB9EA4BD02F469FFAD10CDD58D049D44E1EB74FA5697A098674546D6D0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/src/tests/data/misc/roughtime_response.vec b/src/tests/data/misc/roughtime_response.vec
new file mode 100644
index 000000000..1166c185d
--- /dev/null
+++ b/src/tests/data/misc/roughtime_response.vec
@@ -0,0 +1,67 @@
+[Invalid]
+# Botan::Invalid_Argument:tag not found
+Response = 040000004000000040000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Botan::Invalid_Argument:tag not found
+Response = 050000004000000040000000A40000003C01000054494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Botan::Invalid_Argument:invalid structure
+Response = 05000000400000
+
+# Botan::Invalid_Argument:invalid structure
+Response = 050000004000000050000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Botan::Invalid_Argument:invalid structure
+Response = 050000004000000040000000A40000004C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Botan::Invalid_Argument:invalid structure
+Response = 050000005000000040000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Botan::Invalid_Argument:nonce verification failed
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697292050000000000
+
+# Botan::Invalid_Argument:tag content wrong size
+Response = 050000004000000040000000A40000003C01000050415448534947005352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Botan::Invalid_Argument:Merkle tree path is too short
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000001
+
+# Botan::Invalid_Argument:response signature invalid
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6D148020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Botan::Invalid_Argument:Merkle tree path size must be multiple of 64 bytes
+Response = 0500000040000000C100000025010000BD01000053494700504154485352455043455254494E44583C6348F53968422316DEF44BAAB1D0C55C695B12FA0DC12955DD41768CAE75171C411AB3F39B9B39A0A5F55739B23DA8C9C8AA13EFAFFA36C53B3A5D4C9EB30911709B0F0EA767A0A40ECC06F9AD5D0EE93C4DC95E19A43EF2A92851E3D5CD92EE16FF096C0AC926BBEC6226CF7A15D2C6AB7154D2D4638E17CB01CAE047B9B412B367367A74718F21F1A12318E1EC8FDAAE1D3912F9588EF42A8C2F3F2EF27D45DB472770465181672BB9BC1E306D4767E6EE9D3542C603200127E2D8EBF5C29903000000040000000C000000524144494D494450524F4F5440420F00ABB836DD78820500D85F9F5E8879DD9D5F5130E4F3A8B250FAC244754BA536D2C24D08E59C5CEADA79966B39C10E8678C94529F7790421C4AD490FA43A208D9AEF0BB1DE4252F94202000000400000005349470044454C457865CA05DFFED083CF78A50A24A7D00E7AC2AC27449C9A8CFDA496DBE8ACC74C2C7B766449CBD085AE88C40627EAE8D0F9D07EC30F4D8F37ABB17842ABDC380A0300000020000000280000005055424B4D494E544D415854A9600D58ECE49A48410ABB4F20FDA858ADF5BE3CCCFF09B4ED028DC76A5956560000000000000000FFFFFFFFFFFFFFFF02000000
+
+# Botan::Invalid_Argument:midpoint earlier than delegation start
+Nonce = 71BEFBF21751C7431F05AF1384D4C2355D20E5E9193D2236B2D385A70DEC6AD92B2E8D84178A1E44D94DEB6F2DB1644BE72155DACBEFF00C5E1A69B0E1B11BE3
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E445812E94D200CED7E281CF5197E7C2955019F75087D03C70E3C5365CF9D3328F55F63631CADA236A7A505D32D18AD3D6158A9D0723ECDB11698CE602C88294E360503000000040000000C000000524144494D494450524F4F5440420F00B529B0DFF08205003FD6E7B379BE6CC4D6F104ACAAA2115B773E9D649A16C93689FC3945DF538DC7178E75F6DC2FD348B51ADCB1FA86B445039EF827C61727870B2269A6845CF31902000000400000005349470044454C45FD37B5E344698F85D818C61B1F39D3F2F4E876CE60D62F8B5ED3F892EBC01816A11AF3FBF2D55CCF245876EDBBBD636A701241F4B241AF52EF9020D93D0398000300000020000000280000005055424B4D494E544D4158546A42F3AD4043A8AC60D47A7283EB9EE9D462672483F08E34F8B46C6681D283C730BF9D0EF10F090030BF9D0EF10F090000000000
+
+# Botan::Invalid_Argument:midpoint later than delegation end
+Nonce = A6E107D0F1C7A63620B4696BEC16C9DA19186205F96DA7FD9D2FA6E36C9D5A0C35413CD004F3398DC09A8635A669211DFEEF0F9EC20F2DC8BA5D51BF6314C6C5
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E445850838432248595410821CBD39AA022BBE4AC9AF8F815D0EEF738215C386F9594D71A4DDF7D8AD73C50B4AE28DC6691344C6E869EFC0ACAAA7D74DF4F6398CA0003000000040000000C000000524144494D494450524F4F5440420F004EFF0EDAF082050012532E7C04D6EE62DDB4BC04877D1EBD30B9811858315EBBD011721194A5DD0BE73BE8E06390443D3D3C85E56DF471AFD461DC28FBBEC9C5A0DAF54B982B167802000000400000005349470044454C452DB049AE5FF4411953AC87E783EE9B36A3CF784B57C0BDA954EDE55AC95B1D1756CD55D1CC4F0911E89396A82BBF1F53B71E401C3C244DD81B2A11E8D7D83D000300000020000000280000005055424B4D494E544D41585476AAAB18DD9FA7643796A4E5FCB4F1CE7BF36AB3B8D4CB1B507D935F9F882A2D303FD76972820500303FD7697282050000000000
+
+# fail_validation
+Nonce = 83ED2ACE13F29CF02EFB939A6EC79A4BBB7BE7D9E5854FD083FDB01E64BBDBDFEDA23A9FB9EA4BD02F469FFAD10CDD58D049D44E1EB74FA5697A098674546D6D
+Pubkey = 503eb78528f749c4bec2e39e1abb9b5e5ab7e4dd5ce4b6f2fd2f93ecc3538f1a
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+[Valid]
+Nonce = 83ED2ACE13F29CF02EFB939A6EC79A4BBB7BE7D9E5854FD083FDB01E64BBDBDFEDA23A9FB9EA4BD02F469FFAD10CDD58D049D44E1EB74FA5697A098674546D6D
+Pubkey = 803eb78528f749c4bec2e39e1abb9b5e5ab7e4dd5ce4b6f2fd2f93ecc3538f1a
+MidpointMicroSeconds = 1550755344243000
+RadiusMicroSeconds = 1000000
+Response = 050000004000000040000000A40000003C01000053494700504154485352455043455254494E445889AD80EC2EF7E507FD68E4B88F6DB48020807749BCAE886FE8221D31B5EC070FEB25E401FD746D9C2C995B354FFED67F8FC05B56F4844502F632EAD44FD7140E03000000040000000C000000524144494D494450524F4F5440420F0038596D5D678205008DC2277E99668AF765D3D7372D915B904AD6CEB0BAA4262E194C894C0634936DA2CCD92ADBA30FF286ADF5EBF68A5E7BE43559A6226BD3500DDA16083C11C2A202000000400000005349470044454C45A82675D99316586079BDDF8965030CEA112DAAC1D9EADE089CFB7B7C9ABF7D9F87FFDFBB958FCBAC5BE082FBFC110E8B75E11ECEA3DD6D91348AFADCC045260A0300000020000000280000005055424B4D494E544D41585468B3FAF25B844DE2860ECC833283DEBE12A2852E195758B03AA8E39B5247F35E30DFFF4B5E820500303FD7697282050000000000
+
+# Merkle tree 2 leafs
+Nonce = 8FEBCFDCB149EA09E96405547F5360A2C243169F3243B8BA16B962CC94EF62E5E1A619EA25A18B8F324A63B85B615285A17065BE94592D8C1FDF3FAFF279A6E8
+Pubkey = 6f79ced1b4d650a7bb23325b68a9866da2cf33ffd89f073933a5a6107d55aca1
+MidpointMicroSeconds = 1550830411384409
+RadiusMicroSeconds = 1000000
+Response = 050000004000000080000000E40000007C01000053494700504154485352455043455254494E4458357CD0583B97ADFFB7AB5EFD932661366EEFD6AB5B204FAB2CBD9F1CFBE2314FD953CCC66E280307BB30C004A838202EE12BBAC5CA6BE0D179C13441072A8102FD2915F34A58CB40516E2731B2884051482D829F7A996EC3D1BF7367CE40AB8EF28C8BD6A04063F0BE45FBBBF3C79332CCE35E82E783800B6B1E814ECE7C815903000000040000000C000000524144494D494450524F4F5440420F005906C7D778820500FB6AF62DD67A7EFA90E64E26DE4B93FB6A3455DA1C73ABE30CFA6FA0BCAD1E56F4C133BAE1FE959EECFF6F674A8FFC95148E723C8D08510C2394326A3C595D9202000000400000005349470044454C457865CA05DFFED083CF78A50A24A7D00E7AC2AC27449C9A8CFDA496DBE8ACC74C2C7B766449CBD085AE88C40627EAE8D0F9D07EC30F4D8F37ABB17842ABDC380A0300000020000000280000005055424B4D494E544D415854A9600D58ECE49A48410ABB4F20FDA858ADF5BE3CCCFF09B4ED028DC76A5956560000000000000000FFFFFFFFFFFFFFFF01000000
+
+# Merkle tree 4 leafs
+Nonce = 92DD76EC9302DA565A14D4B7C71AF005DBB51DFE50A931E4BF25925BB9667066E4E593EB8332A57F4CFA14074210AAC5D43A9E4CC13FE5889E9DE0C428AA9D5D
+Pubkey = 6f79ced1b4d650a7bb23325b68a9866da2cf33ffd89f073933a5a6107d55aca1
+MidpointMicroSeconds = 1550830502590635
+RadiusMicroSeconds = 1000000
+Response = 0500000040000000C000000024010000BC01000053494700504154485352455043455254494E44583C6348F53968422316DEF44BAAB1D0C55C695B12FA0DC12955DD41768CAE75171C411AB3F39B9B39A0A5F55739B23DA8C9C8AA13EFAFFA36C53B3A5D4C9EB309709B0F0EA767A0A40ECC06F9AD5D0EE93C4DC95E19A43EF2A92851E3D5CD92EE16FF096C0AC926BBEC6226CF7A15D2C6AB7154D2D4638E17CB01CAE047B9B412B367367A74718F21F1A12318E1EC8FDAAE1D3912F9588EF42A8C2F3F2EF27D45DB472770465181672BB9BC1E306D4767E6EE9D3542C603200127E2D8EBF5C29903000000040000000C000000524144494D494450524F4F5440420F00ABB836DD78820500D85F9F5E8879DD9D5F5130E4F3A8B250FAC244754BA536D2C24D08E59C5CEADA79966B39C10E8678C94529F7790421C4AD490FA43A208D9AEF0BB1DE4252F94202000000400000005349470044454C457865CA05DFFED083CF78A50A24A7D00E7AC2AC27449C9A8CFDA496DBE8ACC74C2C7B766449CBD085AE88C40627EAE8D0F9D07EC30F4D8F37ABB17842ABDC380A0300000020000000280000005055424B4D494E544D415854A9600D58ECE49A48410ABB4F20FDA858ADF5BE3CCCFF09B4ED028DC76A5956560000000000000000FFFFFFFFFFFFFFFF02000000
diff --git a/src/tests/test_roughtime.cpp b/src/tests/test_roughtime.cpp
new file mode 100644
index 000000000..65bd671bb
--- /dev/null
+++ b/src/tests/test_roughtime.cpp
@@ -0,0 +1,264 @@
+/*
+* (C) 2019 Nuno Goncalves <[email protected]>
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "tests.h"
+
+#include <cassert>
+
+#include "test_rng.h"
+
+#if defined(BOTAN_HAS_BIGINT)
+ #include <botan/bigint.h>
+#endif
+
+#if defined(BOTAN_HAS_ROUGHTIME)
+ #include <botan/base64.h>
+ #include <botan/ed25519.h>
+ #include <botan/hex.h>
+ #include <botan/roughtime.h>
+#endif
+namespace Botan_Tests {
+
+#if defined(BOTAN_HAS_ROUGHTIME)
+
+class Roughtime_Request_Tests final : public Text_Based_Test
+ {
+ public:
+ Roughtime_Request_Tests() :
+ Text_Based_Test("misc/roughtime_request.vec", "Nonce,Request") {}
+
+ Test::Result run_one_test(const std::string& type, const VarMap& vars) override
+ {
+ Test::Result result("roughtime request");
+
+ const auto nonce = vars.get_req_bin("Nonce");
+ const auto request_v = vars.get_req_bin("Request");
+
+ const auto request = Botan::Roughtime::encode_request(nonce);
+ result.test_eq(
+ "encode",
+ type == "Valid",
+ request == Botan::typecast_copy<std::array<uint8_t, 1024>>(request_v.data()));
+
+ return result;
+ }
+ };
+
+BOTAN_REGISTER_TEST("roughtime_request", Roughtime_Request_Tests);
+
+
+class Roughtime_Response_Tests final : public Text_Based_Test
+ {
+ public:
+ Roughtime_Response_Tests() :
+ Text_Based_Test("misc/roughtime_response.vec",
+ "Response",
+ "Nonce,Pubkey,MidpointMicroSeconds,RadiusMicroSeconds") {}
+
+ Test::Result run_one_test(const std::string& type, const VarMap& vars) override
+ {
+ Test::Result result("roughtime response");
+
+ const auto response_v = vars.get_req_bin("Response");
+ const auto n = vars.has_key("Nonce") ? vars.get_req_bin("Nonce") : std::vector<uint8_t>(64);
+ assert(n.size() == 64);
+ const Botan::Roughtime::Nonce nonce(n);
+ try
+ {
+ const auto response = Botan::Roughtime::Response::from_bits(response_v, nonce);
+
+ const auto pubkey = vars.get_req_bin("Pubkey");
+ assert(pubkey.size() == 32);
+
+ if(!response.validate(Botan::Ed25519_PublicKey(pubkey)))
+ {
+ result.confirm("fail_validation", type == "Invalid");
+ }
+ else
+ {
+ const auto midpoint = Botan::Roughtime::Response::sys_microseconds64(
+ std::chrono::microseconds(
+ vars.get_req_u64("MidpointMicroSeconds")));
+ const auto radius = std::chrono::microseconds(
+ vars.get_req_u32("RadiusMicroSeconds"));
+
+ result.confirm("midpoint", response.utc_midpoint() == midpoint);
+ result.confirm("radius", response.utc_radius() == radius);
+ result.confirm("OK", type == "Valid");
+ }
+ }
+ catch(const Botan::Roughtime::Roughtime_Error& e)
+ {
+ result.confirm(e.what(), type == "Invalid");
+ }
+
+ return result;
+ }
+ };
+
+BOTAN_REGISTER_TEST("roughtime_response", Roughtime_Response_Tests);
+
+class Roughtime_nonce_from_blind_Tests final : public Text_Based_Test
+ {
+ public:
+ Roughtime_nonce_from_blind_Tests() :
+ Text_Based_Test("misc/roughtime_nonce_from_blind.vec", "Response,Blind,Nonce") {}
+
+ Test::Result run_one_test(const std::string& type, const VarMap& vars) override
+ {
+ Test::Result result("roughtime nonce_from_blind");
+
+ const auto response = vars.get_req_bin("Response");
+ const auto blind = vars.get_req_bin("Blind");
+ const auto nonce = vars.get_req_bin("Nonce");
+
+ result.test_eq("fail_validation",
+ Botan::Roughtime::nonce_from_blind(response, blind) == nonce,
+ type == "Valid");
+
+ return result;
+ }
+ };
+
+BOTAN_REGISTER_TEST("roughtime_nonce_from_blind", Roughtime_nonce_from_blind_Tests);
+
+
+
+class Roughtime final : public Test
+ {
+ Test::Result test_nonce()
+ {
+ Test::Result result("roughtime nonce");
+
+ auto rand64 = Botan::unlock(Test::rng().random_vec(64));;
+ Botan::Roughtime::Nonce nonce_v(rand64);
+ result.confirm("nonce from vector", nonce_v.get_nonce() == Botan::typecast_copy<std::array<uint8_t, 64>>
+ (rand64.data()));
+ Botan::Roughtime::Nonce nonce_a(Botan::typecast_copy<std::array<uint8_t, 64>>(rand64.data()));
+ result.confirm("nonce from array", nonce_v.get_nonce() == Botan::typecast_copy<std::array<uint8_t, 64>>(rand64.data()));
+ rand64.push_back(10);
+ result.test_throws("vector oversize", [&rand64]() {Botan::Roughtime::Nonce nonce_v(rand64);}); //size 65
+ rand64.pop_back();
+ rand64.pop_back();
+ result.test_throws("vector undersize", [&rand64]() {Botan::Roughtime::Nonce nonce_v(rand64);}); //size 63
+
+ return result;
+ }
+
+ Test::Result test_chain()
+ {
+ Test::Result result("roughtime chain");
+
+ Botan::Roughtime::Chain c1;
+ result.confirm("default constructed is empty", c1.links().empty() && c1.responses().empty());
+
+ auto rand64 = Botan::unlock(Test::rng().random_vec(64));;
+ Botan::Roughtime::Nonce nonce_v(rand64);
+ result.confirm("empty chain nonce is blind",
+ c1.next_nonce(nonce_v).get_nonce() == Botan::typecast_copy<std::array<uint8_t, 64>>(rand64.data()));
+
+ const std::string chain_str =
+ "ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= eu9yhsJfVfguVSqGZdE8WKIxaBBM0ZG3Vmuc+IyZmG2YVmrIktUByDdwIFw6F4rZqmSFsBO85ljoVPz5bVPCOw== BQAAAEAAAABAAAAApAAAADwBAABTSUcAUEFUSFNSRVBDRVJUSU5EWBnGOEajOwPA6G7oL47seBP4C7eEpr57H43C2/fK/kMA0UGZVUdf4KNX8oxOK6JIcsbVk8qhghTwA70qtwpYmQkDAAAABAAAAAwAAABSQURJTUlEUFJPT1RAQg8AJrA8tEqPBQAqisiuAxgy2Pj7UJAiWbCdzGz1xcCnja3T+AqhC8fwpeIwW4GPy/vEb/awXW2DgSLKJfzWIAz+2lsR7t4UjNPvAgAAAEAAAABTSUcAREVMRes9Ch4X0HIw5KdOTB8xK4VDFSJBD/G9t7Et/CU7UW61OiTBXYYQTG2JekWZmGa0OHX1JPGG+APkpbsNw0BKUgYDAAAAIAAAACgAAABQVUJLTUlOVE1BWFR/9BWjpsWTQ1f6iUJea3EfZ1MkX3ftJiV3ABqNLpncFwAAAAAAAAAA//////////8AAAAA\n"
+ "ed25519 gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo= uLeTON9D+2HqJMzK6sYWLNDEdtBl9t/9yw1cVAOm0/sONH5Oqdq9dVPkC9syjuWbglCiCPVF+FbOtcxCkrgMmA== BQAAAEAAAABAAAAApAAAADwBAABTSUcAUEFUSFNSRVBDRVJUSU5EWOw1jl0uSiBEH9HE8/6r7zxoSc01f48vw+UzH8+VJoPelnvVJBj4lnH8uRLh5Aw0i4Du7XM1dp2u0r/I5PzhMQoDAAAABAAAAAwAAABSQURJTUlEUFJPT1RAQg8AUBo+tEqPBQC47l77to7ESFTVhlw1SC74P5ssx6gpuJ6eP+1916GuUiySGE/x3Fp0c3otUGAdsRQou5p9PDTeane/YEeVq4/8AgAAAEAAAABTSUcAREVMRe5T1ml8wHyWAcEtHP/U5Rg/jFXTEXOSglngSa4aI/CECVdy4ZNWeP6vv+2//ZW7lQsrWo7ZkXpvm9BdBONRSQIDAAAAIAAAACgAAABQVUJLTUlOVE1BWFQpXlenV0OfVisvp9jDHXLw8vymZVK9Pgw9k6Edf8ZEhUgSGEc5jwUASHLvZE2PBQAAAAAA\n";
+
+ Botan::Roughtime::Chain c2(chain_str);
+ result.confirm("have two elements", c2.links().size() == 2 && c2.responses().size() == 2);
+ result.confirm("serialize loopback", c2.to_string() == chain_str);
+
+ c1.append(c2.links()[0], 1);
+ result.confirm("append ok", c1.links().size() == 1 && c1.responses().size() == 1);
+ c1.append(c2.links()[1], 1);
+ result.confirm("max size", c1.links().size() == 1 && c1.responses().size() == 1);
+
+ result.test_throws("non-positive max chain size", [&]() {c1.append(c2.links()[1], 0);});
+ result.test_throws("1 field", [&]() {Botan::Roughtime::Chain a("ed25519");});
+ result.test_throws("2 fields", [&]() {Botan::Roughtime::Chain a("ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE=");});
+ result.test_throws("3 fields", [&]() {Botan::Roughtime::Chain a("ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= eu9yhsJfVfguVSqGZdE8WKIxaBBM0ZG3Vmuc+IyZmG2YVmrIktUByDdwIFw6F4rZqmSFsBO85ljoVPz5bVPCOw==");});
+ result.test_throws("5 fields", [&]() {Botan::Roughtime::Chain a("ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= eu9yhsJfVfguVSqGZdE8WKIxaBBM0ZG3Vmuc+IyZmG2YVmrIktUByDdwIFw6F4rZqmSFsBO85ljoVPz5bVPCOw== BQAAAEAAAABAAAAApAAAADwBAABTSUcAUEFUSFNSRVBDRVJUSU5EWBnGOEajOwPA6G7oL47seBP4C7eEpr57H43C2/fK/kMA0UGZVUdf4KNX8oxOK6JIcsbVk8qhghTwA70qtwpYmQkDAAAABAAAAAwAAABSQURJTUlEUFJPT1RAQg8AJrA8tEqPBQAqisiuAxgy2Pj7UJAiWbCdzGz1xcCnja3T+AqhC8fwpeIwW4GPy/vEb/awXW2DgSLKJfzWIAz+2lsR7t4UjNPvAgAAAEAAAABTSUcAREVMRes9Ch4X0HIw5KdOTB8xK4VDFSJBD/G9t7Et/CU7UW61OiTBXYYQTG2JekWZmGa0OHX1JPGG+APkpbsNw0BKUgYDAAAAIAAAACgAAABQVUJLTUlOVE1BWFR/9BWjpsWTQ1f6iUJea3EfZ1MkX3ftJiV3ABqNLpncFwAAAAAAAAAA//////////8AAAAA abc");});
+ result.test_throws("invalid key type", [&]() {Botan::Roughtime::Chain a("rsa bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= eu9yhsJfVfguVSqGZdE8WKIxaBBM0ZG3Vmuc+IyZmG2YVmrIktUByDdwIFw6F4rZqmSFsBO85ljoVPz5bVPCOw== BQAAAEAAAABAAAAApAAAADwBAABTSUcAUEFUSFNSRVBDRVJUSU5EWBnGOEajOwPA6G7oL47seBP4C7eEpr57H43C2/fK/kMA0UGZVUdf4KNX8oxOK6JIcsbVk8qhghTwA70qtwpYmQkDAAAABAAAAAwAAABSQURJTUlEUFJPT1RAQg8AJrA8tEqPBQAqisiuAxgy2Pj7UJAiWbCdzGz1xcCnja3T+AqhC8fwpeIwW4GPy/vEb/awXW2DgSLKJfzWIAz+2lsR7t4UjNPvAgAAAEAAAABTSUcAREVMRes9Ch4X0HIw5KdOTB8xK4VDFSJBD/G9t7Et/CU7UW61OiTBXYYQTG2JekWZmGa0OHX1JPGG+APkpbsNw0BKUgYDAAAAIAAAACgAAABQVUJLTUlOVE1BWFR/9BWjpsWTQ1f6iUJea3EfZ1MkX3ftJiV3ABqNLpncFwAAAAAAAAAA//////////8AAAAA");});
+ result.test_throws("invalid key", [&]() {Botan::Roughtime::Chain a("ed25519 bbT+RPS7zKX6wssPibzmwWqU9ffRV5oj2OresSmhE= eu9yhsJfVfguVSqGZdE8WKIxaBBM0ZG3Vmuc+IyZmG2YVmrIktUByDdwIFw6F4rZqmSFsBO85ljoVPz5bVPCOw== BQAAAEAAAABAAAAApAAAADwBAABTSUcAUEFUSFNSRVBDRVJUSU5EWBnGOEajOwPA6G7oL47seBP4C7eEpr57H43C2/fK/kMA0UGZVUdf4KNX8oxOK6JIcsbVk8qhghTwA70qtwpYmQkDAAAABAAAAAwAAABSQURJTUlEUFJPT1RAQg8AJrA8tEqPBQAqisiuAxgy2Pj7UJAiWbCdzGz1xcCnja3T+AqhC8fwpeIwW4GPy/vEb/awXW2DgSLKJfzWIAz+2lsR7t4UjNPvAgAAAEAAAABTSUcAREVMRes9Ch4X0HIw5KdOTB8xK4VDFSJBD/G9t7Et/CU7UW61OiTBXYYQTG2JekWZmGa0OHX1JPGG+APkpbsNw0BKUgYDAAAAIAAAACgAAABQVUJLTUlOVE1BWFR/9BWjpsWTQ1f6iUJea3EfZ1MkX3ftJiV3ABqNLpncFwAAAAAAAAAA//////////8AAAAA");});
+ result.test_throws("invalid nonce", [&]() {Botan::Roughtime::Chain a("ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= eu9yhsJfVfguVSqGZdE8WKIxaBBM0ZG3Vmuc+IyZmG2UByDdwIFw6F4rZqmSFsBO85ljoVPz5bVPCOw== BQAAAEAAAABAAAAApAAAADwBAABTSUcAUEFUSFNSRVBDRVJUSU5EWBnGOEajOwPA6G7oL47seBP4C7eEpr57H43C2/fK/kMA0UGZVUdf4KNX8oxOK6JIcsbVk8qhghTwA70qtwpYmQkDAAAABAAAAAwAAABSQURJTUlEUFJPT1RAQg8AJrA8tEqPBQAqisiuAxgy2Pj7UJAiWbCdzGz1xcCnja3T+AqhC8fwpeIwW4GPy/vEb/awXW2DgSLKJfzWIAz+2lsR7t4UjNPvAgAAAEAAAABTSUcAREVMRes9Ch4X0HIw5KdOTB8xK4VDFSJBD/G9t7Et/CU7UW61OiTBXYYQTG2JekWZmGa0OHX1JPGG+APkpbsNw0BKUgYDAAAAIAAAACgAAABQVUJLTUlOVE1BWFR/9BWjpsWTQ1f6iUJea3EfZ1MkX3ftJiV3ABqNLpncFwAAAAAAAAAA//////////8AAAAA");});
+
+ return result;
+ }
+
+ Test::Result test_server_information()
+ {
+ Test::Result result("roughtime server_information");
+
+ const auto servers = Botan::Roughtime::servers_from_str(
+ "Chainpoint-Roughtime ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= udp roughtime.chainpoint.org:2002\n"
+ "Cloudflare-Roughtime ed25519 gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo= udp roughtime.cloudflare.com:2002\n"
+ "Google-Sandbox-Roughtime ed25519 etPaaIxcBMY1oUeGpwvPMCJMwlRVNxv51KK/tktoJTQ= udp roughtime.sandbox.google.com:2002\n"
+ "int08h-Roughtime ed25519 AW5uAoTSTDfG5NfY1bTh08GUnOqlRb+HVhbJ3ODJvsE= udp roughtime.int08h.com:2002\n"
+ "ticktock ed25519 cj8GsiNlRkqiDElAeNMSBBMwrAl15hYPgX50+GWX/lA= udp ticktock.mixmin.net:5333\n"
+ );
+
+ result.confirm("size", servers.size() == 5);
+ result.test_eq("name", servers[0].name(), "Chainpoint-Roughtime");
+ result.test_eq("name", servers[4].name(), "ticktock");
+ result.confirm("public key", servers[0].public_key().get_public_key() == Botan::Ed25519_PublicKey(
+ Botan::base64_decode("bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE=")).get_public_key());
+ result.confirm("single address", servers[0].addresses().size()==1);
+ result.test_eq("address", servers[0].addresses()[0], "roughtime.chainpoint.org:2002");
+
+ result.test_throws("1 field", [&]() {Botan::Roughtime::servers_from_str("A");});
+ result.test_throws("2 fields", [&]() {Botan::Roughtime::servers_from_str("A ed25519");});
+ result.test_throws("3 fields", [&]() {Botan::Roughtime::servers_from_str("A ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE=");});
+ result.test_throws("4 fields", [&]() {Botan::Roughtime::servers_from_str("A ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= udp");});
+ result.test_throws("invalid address", [&]() {Botan::Roughtime::servers_from_str("A ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= udp ");});
+ result.test_throws("invalid key type", [&]() {Botan::Roughtime::servers_from_str("A rsa bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= udp roughtime.chainpoint.org:2002");});
+ result.test_throws("invalid key", [&]() {Botan::Roughtime::servers_from_str("A ed25519 bbT+RP7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= udp roughtime.chainpoint.org:2002");});
+ result.test_throws("invalid protocol", [&]() {Botan::Roughtime::servers_from_str("A ed25519 bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= tcp roughtime.chainpoint.org:2002");});
+
+ return result;
+ }
+
+ Test::Result test_request_online()
+ {
+ Test::Result result("roughtime request online");
+
+ Botan::Roughtime::Nonce nonce(Test::rng());
+ try
+ {
+ const auto response_raw = Botan::Roughtime::online_request("roughtime.cloudflare.com:2002", nonce,
+ std::chrono::seconds(5));
+ const auto now = std::chrono::system_clock::now();
+ const auto response = Botan::Roughtime::Response::from_bits(response_raw, nonce);
+ std::chrono::milliseconds local_clock_max_error(1000);
+ const auto diff_abs = now >= response.utc_midpoint() ? now - response.utc_midpoint() : response.utc_midpoint() - now;
+ result.confirm("online", diff_abs <= (response.utc_radius() + local_clock_max_error));
+ }
+ catch(const std::exception& e)
+ {
+ result.test_failure(e.what());
+ }
+ return result;
+ }
+
+
+ public:
+ std::vector<Test::Result> run() override
+ {
+ std::vector<Test::Result> results;
+ results.push_back(test_nonce());
+ results.push_back(test_chain());
+ results.push_back(test_server_information());
+
+ if(Test::options().run_online_tests())
+ {
+ results.push_back(test_request_online());
+ }
+
+ return results;
+ }
+ };
+
+BOTAN_REGISTER_TEST("roughtime", Roughtime);
+
+#endif
+
+}