Reverse Engineering Serial Commands - c#

tl;dr;
What I need to be able to do is reverse engineer serial commands so that I can figure out how either the human readable values or the binary values are being serialized into raw serial commands.
IE:
if
66 = 'A1' or '0110 1'
6e = 'A2' or '0110 2'
e6 = 'B1' or '1110 1'
ee = 'B2' or '1110 2'
then
what is A3 or B3, etc.
Im working on a wrapper for an open source automation project.
There is a way to send raw commands, and in theory string multiple commands together.
I've sniffed a few serial commands, and this is what they look like.
[init] [HouseCode | DeviceCode] [ready] [HouseCode | FunctionCode]
04 66 06 62 // A1 ON
04 6e 06 62 // A2 ON
04 62 06 62 // A3 ON
04 6a 06 62 // A4 ON
04 61 06 62 // A5 ON
04 69 06 62 // A6 ON
04 65 06 62 // A7 ON
04 6d 06 62 // A8 ON
04 67 06 62 // A9 ON
04 6f 06 62 // A10 ON
04 63 06 62 // A11 ON
04 6b 06 62 // A12 ON
04 60 06 62 // A13 ON
04 68 06 62 // A14 ON
04 64 06 62 // A15 ON
04 6c 06 62 // A16 ON
04 e6 06 e2 // B1 ON
04 ee 06 e2 // B2 ON
04 e2 06 e2 // B3 ON
04 ea 06 e2 // B4 ON
....
04 ec 06 e2 // B16 ON
04 66 06 63 // A1 Off
04 e6 06 e3 // B1 Off
04 66 06 61 // All A lights On (using A1 as the starting point)
04 e6 06 e1 // All B lights On (using B1 as the starting point)
04 66 06 66 // All A lights Off (using A1 as the starting point)
04 e6 06 66 // All B lights Off (using A1 as the starting point)
04 66 06 64 2a // A1 Dim 20
04 66 06 64 2c // A1 Dim 21
04 66 06 64 2e // A1 Dim 22
04 66 06 65 2a // A1 Bright 20
04 66 06 65 69 // A1 Bright 50
What I need to be able to do is reverse engineer this so that I can make the serial calls programmatically, or better yet, figure out how either the human readable values or the binary values are being serialized into raw serial commands.
Yes, I could sniff ALL the commands and store each value separately, but I'd like to know how this has been done.
Here's my current observation.
The calls are broken up into two.
04 is initiated and tells the device what to look for
** tells the system which device is being controlled [HouseCode & DeviceCode]
hex 55 is returned to tell you it's ready
06 is initiated and tells the device what to expect
** tells the system the house code and command [HouseCode & FunctionCode]
** is optionally sent and is a value between 0 & 100 to reference a dim level
hex 55 is sent back again to tell you it's ready
The second pair uses the first character as the alphabetic code (HouseCode = A, B, C, etc) and the second character is the address (DeviceCode = 1, 2, 3, etc)
with this information, my personal guess is that...
6 must directly correspond to A
e must directly correspond to B
The forth pair starts with the same HouseCode as the second pair
The forth pair ends with the FunctionCode
1 = all on
2 = on
3 = off
4 = dim
5 = bright
6 = all off
etc..
The fifth pair only shows on a bright/dim command and represents the number between 0 and 100
Lastly, in the docs, each of the commands relate to Binary data, so it's probably not a matter of converting A1 to hex, but rather the binary to hex.
HouseCode DeviceCode Binary Value
A 1 0110
B 2 1110
C 3 0010
D 4 1010
E 5 0001
F 6 1001
G 7 0101
H 8 1101
I 9 0111
J 10 1111
K 11 0011
L 12 1011
M 13 0000
N 14 1000
O 15 0100
P 16 1100
FunctionCode Binary Value
All Units Off 0000
All Lights On 0001
On 0010
Off 0011
Dim 0100
Bright 0101
All Lights Off 0110
Extended Code 0111
Hail Request 1000
Hail Acknowledge 1001
Pre-set Dim (1) 1010
Pre-set Dim (2) 1011
Extended Data Transfer 1100
Status On 1101
Status Off 1110
Status Request 1111
Does anyone know how I might go about achieving this?

Heyu is a fantastic open source application for working with X10 devices. They have published a very comprehensive X10 protocol specification based on X10's original doc.
This should take the guess work out of your work. What is significant is that the housecode and unitcode are static maps and can not be computed. The protocol spec specifies exactly how the bitstream is formed. E.g.
PC Interface Description
0x04,0x66 Address A1
0x6a Checksum ((0x04 + 0x66)&0xff)
0x00 OK for transmission.
0x55 Interface ready.
0x86,0x64 Function: A Dim 16/22*100%
0xea Checksum ((0x86 + 0x64)&0xff)
0x00 OK for transmission.
0x55 Interface ready.

Related

TLS/SSL RABBIT MQ (Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..)

TLS/SSL following steps as:
To create the root CA certificate
genrsa -des3 -out CA-key.pem 2048
req -new -key CA-key.pem -x509 -days 1000 -out CA-cert.pem -subj "/C=US/ST=Oregon/L=Portland/O=user/OU=Org/CN=right.xcl.one"
To create a Signing a Server Certificate:
genrsa -des3 -out server-key.pem 2048
req –new –config openssl.cnf –key server-key.pem –out signingReq.csr
x509 -req -days 365 -in signingReq.csr -CA CA-cert.pem -CAkey CA-key.pem -CAcreateserial -out server-cert.pem
Client Certificate :-
pkcs12 -export -out client-cert.p12 -inkey server-key.pem -in server-cert.pem
Server RabbitMQ Config:-
[
{rabbit, [
{auth_mechanisms, ['EXTERNAL']},
{loopback_users, []},
{ssl_listeners, [5671]},
{ssl_options, [{cacertfile,"D:/RabbitMQ/certs/CA-cert.pem"},
{certfile,"D:/RabbitMQ/certs/server-cert.pem"},
{keyfile,"D:/RabbitMQ/certs/server-key.pem"},
{verify,verify_peer},
{password, "test"},
{fail_if_no_peer_cert, false}]
}
]}
].
In C# Calling from local:-
var hostName = "right.xcl.one";
var cf = new ConnectionFactory
{
HostName = hostName,
UserName = "user",
Password = "user",
VirtualHost = "/",
AuthMechanisms = new IAuthMechanismFactory[] { new ExternalMechanismFactory() },
Ssl = new SslOption
{
Enabled = true,
ServerName = "right.xcl.one",
AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch |
SslPolicyErrors.RemoteCertificateChainErrors,
CertPath = #"D:\client-cert.p12",
CertPassphrase = "test",
}
};
using (IConnection conn = cf.CreateConnection())
OpenSSL> s_client -connect malta1597.startdedicated.com:5671 -cert client-cert.pem -key client-key.pem -CAfile CA-cert.pem -verify 8 -verify_hostname malta1597.startdedicated.com\ -state -debug
verify depth is 8
Enter pass phrase for client-key.pem:
CONNECTED(00000144)
SSL_connect:before SSL initialization
write to 0x1924d107020 [0x1924d1267b0] (330 bytes => 330 (0x14A))
0000 - 16 03 01 01 45 01 00 01-41 03 03 f7 84 a2 00 f6 ....E...A.......
0010 - 82 f2 f0 ef 26 79 3d fb-56 dd f9 37 79 fd 19 58 ....&y=.V..7y..X
0020 - 81 c8 a0 bc b3 5f f3 b5-29 a3 73 20 f8 06 9d 28 ....._..).s ...(
0030 - ec eb 1b c8 e6 f8 4f fe-97 1c 74 23 93 8f db ef ......O...t#....
0040 - 8a ad 18 af 71 96 c2 40-b1 99 9d 92 00 3e 13 02 ....q..#.....>..
0050 - 13 03 13 01 c0 2c c0 30-00 9f cc a9 cc a8 cc aa .....,.0........
0060 - c0 2b c0 2f 00 9e c0 24-c0 28 00 6b c0 23 c0 27 .+./...$.(.k.#.'
0070 - 00 67 c0 0a c0 14 00 39-c0 09 c0 13 00 33 00 9d .g.....9.....3..
0080 - 00 9c 00 3d 00 3c 00 35-00 2f 00 ff 01 00 00 ba ...=.<.5./......
0090 - 00 00 00 21 00 1f 00 00-1c 6d 61 6c 74 61 31 35 ...!.....malta15
00a0 - 39 37 2e 73 74 61 72 74-64 65 64 69 63 61 74 65 97.startdedicate
00b0 - 64 2e 63 6f 6d 00 0b 00-04 03 00 01 02 00 0a 00 d.com...........
00c0 - 0c 00 0a 00 1d 00 17 00-1e 00 19 00 18 00 23 00 ..............#.
00d0 - 00 00 16 00 00 00 17 00-00 00 0d 00 30 00 2e 04 ............0...
00e0 - 03 05 03 06 03 08 07 08-08 08 09 08 0a 08 0b 08 ................
00f0 - 04 08 05 08 06 04 01 05-01 06 01 03 03 02 03 03 ................
0100 - 01 02 01 03 02 02 02 04-02 05 02 06 02 00 2b 00 ..............+.
0110 - 09 08 03 04 03 03 03 02-03 01 00 2d 00 02 01 01 ...........-....
0120 - 00 33 00 26 00 24 00 1d-00 20 d3 71 9e 9a b6 7d .3.&.$... .q...}
0130 - 1f 40 6c f3 35 dc b0 86-bc 52 c9 7e ba b8 64 0b .#l.5....R.~..d.
0140 - d7 09 df b9 a5 34 15 f4-0f 1e .....4....
SSL_connect:SSLv3/TLS write client hello
read from 0x1924d107020 [0x1924d11d593] (5 bytes => -1 (0xFFFFFFFF))
SSL_connect:error in SSLv3/TLS write client hello
write:errno=10054
no peer certificate available
No client certificate CA names sent
SSL handshake has read 0 bytes and written 330 bytes
Verification: OK
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
read from 0x1924d107020 [0x1924d0fb0a0] (8192 bytes => -1 (0xFFFFFFFF))
error in s_client
OpenSSL>
Authenticated successfully but the error is now:-
One or more errors occurred. (Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..)
Please help.

Why Does BouncyCastle Generate Keys Smaller Than .Net's ECDiffieHellmanCng

I'm trying to generate a public key with BouncyCastle (because I'm using Unity and do not have access to ECDiffieHellmanCng), and then I transfer the public key to the server which is using ECDiffieHellmanCng for its key handling.
The server is rejecting my key, for what appears to be because of its small length. ECDiffieHellmanCng generates a public key that is much larger in size compared to that of what Bouncy castle generates.
Is there a way to generate a larger key in bouncy castle?
I tried changing the keybit size, but get an error saying: InvalidParameterException: unknown key size.
Key that BouncyCastle generates:
3059301306072A8648CE3D020106082A8648CE3D03010703420004272F71C1D8B3DC0A7FCB1E9650EEF64EA8F639BEC97D49F8848455C2F5869F7324332D188129C84727F834EE7EE7D8EB7DFC8D40CD4ED219A4FBCEF6C15200F3
Key that ECDiffieHellmanCng generates:
45434B35420000000055CC8665A66A7CDF2E9BF7C69A25B322C72CDBDB1EA8F348050B0A7CF32F9AAD890EA513583367977D5157B2F7FBF55661C9AE2DBAF09B1DC1EA8F193688C3C09501BEE326867ABCB41CA1029F66AF888649F0A6C0674D19670CF32461BA7B3867C1623D68829A7A9A7F1CFC6F5DB99E13C8D960AEF6F5CDAB5B3B62ED6CBEC7222C9F
Here is the code thats generating the bouncy castle key:
const string Algorithm = "ECDH";
const int KeyBitSize = 256;
const int NonceBitSize = 128;
const int MacBitSize = 128;
const int DefaultPrimeProbability = 30;
IAsymmetricCipherKeyPairGenerator aliceKeyGen = GeneratorUtilities.GetKeyPairGenerator(Algorithm);
DHParametersGenerator aliceGenerator = new DHParametersGenerator();
aliceGenerator.Init(KeyBitSize, DefaultPrimeProbability, new SecureRandom());
DHParameters aliceParameters = aliceGenerator.GenerateParameters();
KeyGenerationParameters aliceKGP = new DHKeyGenerationParameters(new SecureRandom(), aliceParameters);
aliceKeyGen.Init(aliceKGP);
AsymmetricCipherKeyPair aliceKeyPair = aliceKeyGen.GenerateKeyPair();
IBasicAgreement aliceKeyAgree = AgreementUtilities.GetBasicAgreement(Algorithm);
aliceKeyAgree.Init(aliceKeyPair.Private);
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(aliceKeyPair.Public);
byte[] serializedPublicBytes = publicKeyInfo.ToAsn1Object().GetDerEncoded();
string serializedPublic = AsString(serializedPublicBytes);
public static string AsString(byte[] bytes, bool keepDashes = false)
{
string hex = BitConverter.ToString(bytes);
return (keepDashes ? hex : hex.Replace("-", ""));
}
I also tried the Mentalis.org DH library, which gives me a larger key, but still just a hair too short.
// create a new DH instance
DiffieHellman dh1 = new DiffieHellmanManaged();
// generate the public key of the first DH instance
byte[] ke1 = dh1.CreateKeyExchange();
string publicKeyString = AsString(ke1);
Key from mentalis.org library:
5F4542F9A8F5636ECCBBAC38238C97ABE757B8F65E25B181BCF41C58985E699EFD6B9606B99F7074717E83F7AC1B5E97DFF6DBA94876F74645F25F0D7FAA1528898C1BD0BB568DF15A98724093766B213769893A05B47E40410B0F395C834F68F57B2EE01852895D912C1D56675A7D8C5367B5E06DE08AAA18CBB4C69F3AE142
If you were to decode the BouncyCastle version you'd see that it is
30 59
SEQUENCE
30 13
SEQUENCE
06 07 2A 86 48 CE 3D 02 01
OBJECT IDENTIFIER 1.2.840.10045.2.1 (id-ecPublicKey)
06 08 2A 86 48 CE 3D 03 01 07
OBJECT IDENTIFIER 1.2.840.10045.3.1.7 (id-secp256r1)
03 42 00
BIT STRING
04 27 2F 71 C1 D8 B3 DC 0A 7F CB 1E 96 50 EE F6
4E A8 F6 39 BE C9 7D 49 F8 84 84 55 C2 F5 86 9F
73 24 33 2D 18 81 29 C8 47 27 F8 34 EE 7E E7 D8
EB 7D FC 8D 40 CD 4E D2 19 A4 FB CE F6 C1 52 00
F3
The BIT STRING's payload is the encoded value of an ecPublicKey whose curve is secp256r1.
Then, following 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion from the SEC-1 paper we see that it's encoded as
04
Uncompressed Point
X = 27 2F 71 C1 D8 B3 DC 0A 7F CB 1E 96 50 EE F6 4E
A8 F6 39 BE C9 7D 49 F8 84 84 55 C2 F5 86 9F 73
Y = 24 33 2D 18 81 29 C8 47 27 F8 34 EE 7E E7 D8 EB
7D FC 8D 40 CD 4E D2 19 A4 FB CE F6 C1 52 00 F3
Following the logic from the .NET Core import/export ECC feature we see that the equivalent CNG blob is
// BCRYPT_ECDH_PUBLIC_P256_MAGIC (little-endian)
45 43 B4 31
// cbKey=(DWORD)32 (little-endian)
20 00 00 00
// The X bytes (big-endian):
27 2F 71 C1 D8 B3 DC 0A 7F CB 1E 96 50 EE F6 4E
A8 F6 39 BE C9 7D 49 F8 84 84 55 C2 F5 86 9F 73
// The Y bytes (big-endian):
27 2F 71 C1 D8 B3 DC 0A 7F CB 1E 96 50 EE F6 4E
A8 F6 39 BE C9 7D 49 F8 84 84 55 C2 F5 86 9F 73

Decompressing Animated GIF Raster Data

Sorry for the lengthy post I'm trying to give as much information as I can and I did my best to format everything to be as easily readable as possible. I've been trying to decompress GIF's in C# and seem to have everything except the LZW decompression down. I am reading in the Gif from a URL. For this example, I will be using this Animated GIF. Which I know has 35 Frames but I only want to look at the first one.
HEADER: 474946383961
GIF Version: 89a
LOGICAL DESCRIPTOR: 41003D00F60000
Width : 65
Height: 61
Sorted Color Table: False
Global Color Table Size: 128
Background Color Index: 0
Pixel Bits: 0
Below is the Global Color Table, something I am slightly confused about because it is filled 123/128 colors and the rest are 000000s, do I discredit this while filling the code table?
Sorry about the format here, only showing it for the question regarding the 000000s
Global Color Table:
141414 181818 1C1C1C 242424 262626 282828 2A2A2A 2C2C28 302C2C 30302C 3430303 434303
434344 030185 030284 03C346 038306 438306 43C305 044245 048245 448285 C50285C 502C5C
542C5C 543054 503860 542C68 50286C 50286C 542870 542870 542C70 582874 582870 582C745
82C745 C2C785 C2C605 830645 830645 C30645 C34685 C307C6 02C6C6 0346C6 438746 434786
030786 838786 C3C006 464806 02C806 42C806 430846 C34886 C348C7 034847 43C887 0388C7
43C887 83C8C7 83C907 034947 034947 434987 434947 438987 4389C7 8389C7 C38A07 838A07
C388C7 C40A46 050A48 03C948 048A08 848A08 C48A89 04CA89 44CAC9 44CAC9 850B09 C50B49
C50B49 C54B4A 054BCA 050B8A 054B8A 454BCA 454BCA 458BCA C5CC0A 454C0A 854C0A 858C4A
858C4A C58C4A C5CC8A C58C8A C5CC4B 058C8B 058C8B 05CC89 C64C8B 060CCB 460D0B 860D0B
864D4B C64D4C 068D8C 068D8C 468DCC 468DCC 86CE8D 070ECD 874F0D C78F4D C78F4D C7CF4E
078F8E 07CF8E 47C000 000000 000000 000000 000000 000000
Graphics Control Extension
21F9040D03007B00 |Graphics Control Extension
Block Size: 4
Has Transparency: True
Delay: 768
Transparency Color Index: 123
Image Descriptor
IMAGE DESCRIPTOR: 2C0000000041003D0000
Left: 0
Top: 0
Width : 65
Height: 61
Local Color Table: False
Interlace: False
Finally Where I am confused the Image Data
LZW minimum code size: 7
IMAGE DATA SUBBLOCK 1 HEXDATA:
80 7B 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 86 06 06 90 94 84 07
95 86 05 0C 00 98 94 05 01 07 05 9D 7B 05 0B 9B A3 8F 07 0C 0C 02 05
93 94 07 08 0A 09 9C A8 8D 05 08 B2 04 02 AF A9 09 0B 0A B5 B6 8B 05
00 C0 AB 01 A2 8E 05 BF C0 C2 C3 8A 07 0A 08 AB 0F 19 CA 8C A5 C0 0B
CF D0 88 C5 0C 09 0C 08 6E 29 CB 0C 0B A6 DD DE 87 9A E9 4C 67 2A D8
89 06 0C 0A E9 08 EB EC 85 06 00 BF 58 63 C6 C8 5B 64 40 4B BA 05 B4
F6 11 03 F0 20 60 18 37 03 E9 85 41 90 4E 43 05 85 C4 AA 9C 39 43 E6
8C 0C 15 8A 0A 98 E9 58 A6 0A 05 8C 21 29 90 21 33 86 0C 98 88 99 C0
8C D9 38 E6 22 CA 90 13 58 86 21 23 05 45 81 9F 40 81 5A 09 C8 F2 E4
CD 94 1D 37 5C D0 93 A7 A9 D3 A6 2A 7C 8C 34 63 F2 28 B1 09 14 EE D8
A9 B3 B5 8E 57 AE 76 B8 AC 68 49 66 82 D5 6C 75 E2 A8 55 0B 67 6D 1C
For All intensive purposes We should need to look at the first few binary bits
IMAGE BLOCK BINARY:
10000000 clearcode, 01111011, 10000010, 10000011, 10000100,
10000101, 10000110, 10000111, 10001000, 10001001, 10001010,
10001011, 10001100, 10001101, 10001110, 10001111,
Codes:
1000000, 0011110, 1110000, 01010000... ect
My main question is how do I use LSB Packing order when reading these codes, secondly how does this make sense for each pixel considering the background is transparent, like how do I get the index of the first non transparent pixel. Finally, at what point do I increase the code size for adding codes to the table to LZW Minimum codes size +1(8). Thank you for any advice.
LSB packing order just means to read the data as little-endian and right shift the data as you "eat" the bits.
Here's an example in C, C# makes accessing memory more painful, but the logic would be the same:
uint32_t ulBits;
unsigned char *pData;
int codelen, code, bitnum;
int mask;
int nextcode;
codelen = 7; // assume 7 bits to start
mask = (1<<(codelen+1)) -1;
clearcode = (mask >> 1) + 1;
nextcode = clearcode + 2;
ulBits = *(uint32_t)pData; // read 32-bits as little endian
bitnum = 0;
#define WORDLEN 32
// To read the variable length codes you would do the following:
while (decoding == true)
{
if ((bitnum + codelen) > WORDLEN) // need to read more data
{
pData += (bitnum >> 3); // adjust source pointer
ulBits = *(uint32_t)pData; // read another 32-bits
bitnum &= 7; // reset bit offset
}
code = (ulBits >> bitnum);
code &= mask;
bitnum += codelen;
// some logic here to increment the nextcode is beyond the scope of this answer
<the rest of your logic here>
}
As you decompress the codes, you add a new item to your dictionary and increment your "next code" value. When this value can't fit in the current code size, you increase it by one bit until you hit 4096 and usually start over with a clear code to reset the dictionary. There is a rarely used option called "differed clear code". In this case the full dictionary stays in use until a clear code is received. There are plenty of sample LZW decoders that you can look at, so it's not necessary to post an entire one here.

Receiving strange output using SerialPort for a Toledo module (scale device)

I'm currently working with a client, and have been requested to accommodate some intake of a legacy Toledo module from the early '80s. The manual I was given by the technicians was for a 8530 DigiTOL INDICATOR
The process is through serial and I'm using .Net SerialPort class. Everything seems to be going well. But the output is of something I can't recognize. I can't seem to achieve any successful encoding of the output nor is the manual of use.
I've updated a bit, perhaps and hopefully in the correct direction. However the output is still garbage.
Code:
public static void Open(String portName)
{
try
{
serialPort = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One)
{
Handshake = Handshake.None,
DtrEnable = true,
RtsEnable = true,
Encoding = System.Text.Encoding.GetEncoding(28591),
};
serialPort.DataReceived += serialPort_OnDataReceived;
serialPort.ErrorReceived += serialPort_ErrorReceived;
shutdown = false;
serialPort.Open();
Console.WriteLine("Connection open on {0}", portName);
}
catch (Exception ex)
{
Console.WriteLine("Connection failed on {0}. {1}", portName, ex.Message);
}
}
private static void serialPort_OnDataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
Console.WriteLine("Data received...");
StringBuilder b = new StringBuilder();
Encoding encoder = Encoding.Default;
while (serialPort.BytesToRead > 0 || shutdown)
{
b.AppendFormat("{0:x2}", serialPort.ReadByte());
b.AppendFormat(" ");
}
Console.WriteLine(b.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Could not read data from port {0}. {1}", serialPort.PortName, ex.Message);
}
}
However as stated, this is still outputting untranslatable data.
Example of output (Hex)
Connection open on COM1
82 3e 14 16
0b c1 b0 58 58 2c 16 16
0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58 58 2c 16 16
0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
82 3e 14 16 0b c1 b0 58
58 2c 16 16 0b 0b 35
Connection closed on COM1
This translates to:
Á ° X X ,
5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X X ,
5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Á ° X
X , 5
Here is a screenshot of the output PuTTY displays w/ same baud rate, parity, data and stop bit
http://i58.tinypic.com/mj9yk3.png
UPDATE
So I have spoken with the technicians. I am receiving errors. Since I could not make sense of it before, and at the time overlooked it. I receive a Frame error every other message received. From looking around I see this could mean a few things. Baud rate mismatches, serial line is too long or there's a lot of electrical noise on the serial cable. I can confirm my software, windows and the module all have the same setup which is Baud rate 9600, Data bits 8, Parity none and Stop bits 1. I can also confirm the manual for this confirms this is a valid setup.
Technicians figured it out! The manual we had was not the original, perhaps not even for our exact model. Regardless, it had suggested to me a baud rate of 9600, data bits of 8, no parity and 1 stop bit was a valid configuration and should work. This was wrong for our device model and apparently not supported (though the device was set and seemed to support a 9600 baud rate -- options were available in setup mode).
It appears the correct configuration is baud rate of 4800, 7 data bits no parity and 1 stop bit.
With this it worked beautifully and I get the data I'm looking for! :)
Thanks everyone.

Reading a ASN.1 DER-encoded RSA Public key

I'm writing an app to get a better understanding of DKIM. The spec says I retrieve a "ASN.1 DER-encoded" public key from the domain TXT record. I can seen the key on "s1024._domainkey.yahoo.com" = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfm".
How can I use this key from .net? The examples I've seen get the key from a X509Certificate2, or an XML file containing the RSAParameters.
CORRECTION: I copy/pasted the key above from the network-tools.com DNS tool, which must've cut it short. nslookup gives me the full key:
s1024._domainkey.yahoo.com text =
"k=rsa; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfm"
"JiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bTxhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj+XcwIDAQAB; n=A 1024 bit key;"
So abelenky was on the right track with BASE64..
This is the base64-encoding of the DER-encoding of an ASN.1 PublicKeyInfo containing an RSA public key.
Here is a translation:
0 30 159: SEQUENCE {
3 30 13: SEQUENCE {
5 06 9: OBJECT IDENTIFIER '1 2 840 113549 1 1 1'
16 05 0: NULL
: }
18 03 141: BIT STRING 0 unused bits, encapsulates {
22 30 137: SEQUENCE {
25 02 129: INTEGER
: 00 EB 11 E7 B4 46 2E 09 BB 3F 90 7E 25 98 BA 2F
: C4 F5 41 92 5D AB BF D8 FF 0B 8E 74 C3 F1 5E 14
: 9E 7F B6 14 06 55 18 4D E4 2F 6D DB CD EA 14 2D
: 8B F8 3D E9 5E 07 78 1F 98 98 83 24 E2 94 DC DB
: 39 2F 82 89 01 45 07 8C 5C 03 79 BB 74 34 FF AC
: 04 AD 15 29 E4 C0 4C BD 98 AF F4 B7 6D 3F F1 87
: 2F B5 C6 D8 F8 46 47 55 ED F5 71 4E 7E 7A 2D BE
: 2E 75 49 F0 BB 12 B8 57 96 F9 3D D3 8A 8F FF 97
: 73
157 02 3: INTEGER 65537
: }
: }
: }
The OBJECT IDENTIFIER indicates that the following BIT STRING contains the encoding of an RSAPublicKey. The INTEGERs are the modulus and the public exponent.
You can decode the base64 with Convert.FromBase64String, but I don't think .NET has built-in functionality for parsing PublicKeyInfos, so you need to use a 3rd party tool like BouncyCastle.
For anyone interested in this matter I would suggest the System.Security.Cryptography.X509Certificates.PublicKey which can be used to read a DER encoded public key.
That string looks like its some sort of base-64 encoding.
If you convert that string from base-64 to a BLOB, it should then be in valid ASN.1 format.
Try the bouncycastle library, it provides great functionality for such cases.

Categories