server session CHANGE support for PKCS#8 keys

Refs #224
diff --git a/src/session_server_ssh.c b/src/session_server_ssh.c
index 329c152..3069ae6 100644
--- a/src/session_server_ssh.c
+++ b/src/session_server_ssh.c
@@ -69,18 +69,30 @@
     }
 
     /* write the key into the file */
-    written = fwrite("-----BEGIN ", 1, 11, file);
-    written += fwrite(key_str, 1, strlen(key_str), file);
-    written += fwrite(" PRIVATE KEY-----\n", 1, 18, file);
-    written += fwrite(in, 1, strlen(in), file);
-    written += fwrite("\n-----END ", 1, 10, file);
-    written += fwrite(key_str, 1, strlen(key_str), file);
-    written += fwrite(" PRIVATE KEY-----", 1, 17, file);
+    if (key_str) {
+        written = fwrite("-----BEGIN ", 1, 11, file);
+        written += fwrite(key_str, 1, strlen(key_str), file);
+        written += fwrite(" PRIVATE KEY-----\n", 1, 18, file);
+        written += fwrite(in, 1, strlen(in), file);
+        written += fwrite("\n-----END ", 1, 10, file);
+        written += fwrite(key_str, 1, strlen(key_str), file);
+        written += fwrite(" PRIVATE KEY-----", 1, 17, file);
 
-    fclose(file);
-    if ((unsigned)written != 11 + strlen(key_str) + 18 + strlen(in) + 10 + strlen(key_str) + 17) {
-        unlink(path);
-        return NULL;
+        fclose(file);
+        if ((unsigned)written != 11 + strlen(key_str) + 18 + strlen(in) + 10 + strlen(key_str) + 17) {
+            unlink(path);
+            return NULL;
+        }
+    } else {
+        written = fwrite("-----BEGIN PRIVATE KEY-----\n", 1, 28, file);
+        written += fwrite(in, 1, strlen(in), file);
+        written += fwrite("\n-----END PRIVATE KEY-----", 1, 26, file);
+
+        fclose(file);
+        if ((unsigned)written != 28 + strlen(in) + 26) {
+            unlink(path);
+            return NULL;
+        }
     }
 
     return strdup(path);