From 05478b26f6a86990a0524418d9dc235d51bc097d Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 29 Aug 2011 11:06:00 -0700 Subject: [PATCH] bug 11262: validate public key before processing it status 11262: resolved fixed --- utils/src/com/cloud/utils/ssh/SSHKeysHelper.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java b/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java index 85eae351976..8f286bb9c2d 100644 --- a/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java +++ b/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java @@ -18,16 +18,16 @@ package com.cloud.utils.ssh; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.KeyPair; -import com.jcraft.jsch.JSch; - import java.io.ByteArrayOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import org.apache.commons.codec.binary.Base64; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.KeyPair; + public class SSHKeysHelper { private KeyPair keyPair; @@ -56,6 +56,9 @@ public class SSHKeysHelper { public static String getPublicKeyFingerprint(String publicKey) { String key[] = publicKey.split(" "); + if (key.length < 2) { + throw new RuntimeException("Incorrect public key is passed in"); + } byte[] keyBytes = Base64.decodeBase64(key[1]); MessageDigest md5 = null;