Sunday, January 30, 2011

How to extract exponents and modulus from SSH-RSA key files

Programmer Question

http://www.faqs.org/rfcs/rfc4253.html

::http://www.faqs.org/rfcs/rfc4251.html



Does anyone know the SSH key file format?



!! UPDATE

!! The base64 function I was using doesn't work. After running the key file through a different function (mozilla's built in atob()) the data fit into the specifications listed above.



I have rsa key files created with puttygen, but I must be missing something critical. Here is the hex of the public section:



00 00 00 07 73 73 68 2d 72 73 61 00 00 00 01 25
00 00 00 10 1c 1c 57 3f 4f 58 63 69 38 ad 19 35
b5 28 3d 78 53 35 53 6c 15 0e 69 23 ac 17 14 84
21 29 13 07 36 62 90 26 37 93 73 17 28 b8 ce 95
c3 11 24 21 61 b7 82 d9 04 42 97 f8 27 c3 44 06
46 ca e8 a3 a3 34 d7 3c c3 95 13 dd 16 1b 2c 29
7c 35 19 5f c2 7a 17 d5 14 0d 26 36 27 18 71 67
8d 9c 5b c4 7d


first 4 bytes are UINT 7, the number of bytes inthe following string "ssh-rsa" but the format stops making sense after that. It SHOULD be followed by two MPINT but they lengths don't add up for the 3rd value.



Thanks!



Find the answer here

Using a numbered file descriptor from Java

Programmer Question

I need to access numbered file descriptors from Java -- other than 0, 1 or 2.



How can this be done? I looked at the FileDescriptor class but did'nt find any way to initialize it with a given file descriptor number.



As a concrete example lets suppose Java gets called as a child process from another programing language. File descriptors 3 and 4 are provided by the other language for input and output.



What I need in Java are InputStream and OutputStream objects connected to these file-descriptors, just like System.in, System.out and System.error are connected to file-desctiptors 0, 1 and 2.



I'm using Java 1.6 and this should run on Unix alike systems.



Tested working solution:



The answer with the file descriptor special filesystem entries did point me to the following workable solution:




  1. find out if and where your Unix alike system has a special filesystem that contains named entries for all file descriptors.




    • I'm using FreeBSD where fdescfs(5) is a filesystem that does just this. Under Linux it would be procfs.


  2. make sure this filesystem is mounted




    • FreeBSD: put fdescfs /dev/fd fdescfs rw 0 0 in /etc/fstab



      or run mount -t fdescfs null /dev/fd on a shell prompt (probably with sudo)



  3. Use new FileInputStream("/dev/fd/3") and new FileOutputStream("/dev/fd/4") to get the streams connected to the filedescriptors (the paths are for FreeBSD, replace with your operating systems paths)




Find the answer here

Saturday, January 29, 2011

Checking a null value in Objective-C that has been returned from a JSON string

Programmer Question

Heya,



I have a JSON object that is coming from a webserver.



The log is something like this:
{"status":"success","UserID":15,"Name":"John","DisplayName":"John","Surname":"Smith","Email":"email","Telephone":null,"FullAccount":"true"}



Note the Telephone is coming in as null if the user doesn't enter one.



When assigning this value to a NSString, in the NSLog it's coming out as



What is the correct way to check this value? It's preventing me from saving a NSDictionary.



I have tried using the conditions [myString length] and myString == nil and myString == NULL



Additionally where is the best place in the iOS documentation to read up on this?



Many thanks



Find the answer here

LinkWithin

Related Posts with Thumbnails