directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: [DIRKRB-239]-Implement the interface RadomProvider.Contributed by Yaning.
Date Thu, 14 May 2015 08:03:23 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master f186424f4 -> 12ac895f8


[DIRKRB-239]-Implement the interface RadomProvider.Contributed by Yaning.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/12ac895f
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/12ac895f
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/12ac895f

Branch: refs/heads/master
Commit: 12ac895f80c773d7108d3167108f2597797718d1
Parents: f186424
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Thu May 14 16:08:01 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Thu May 14 16:08:01 2015 +0800

----------------------------------------------------------------------
 .../kerberos/kerb/crypto/random/JavaRandom.java | 47 ++++++++++++++
 .../kerb/crypto/random/NativeRandom.java        | 67 ++++++++++++++++++++
 2 files changed, 114 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/12ac895f/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java
new file mode 100644
index 0000000..bc20330
--- /dev/null
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java
@@ -0,0 +1,47 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.crypto.random;
+
+import java.security.SecureRandom;
+
+/**
+ * Use jdk SecureRandom to implement RandomProvider, so it can be used on windows & linux.
+ */
+
+public class JavaRandom implements RandomProvider {
+    private SecureRandom random = new SecureRandom();
+    @Override
+    public void init() {
+    }
+
+    @Override
+    public void setSeed(byte[] seed) {
+        random.setSeed(seed);
+    }
+
+    @Override
+    public void nextBytes(byte[] bytes) {
+        random.nextBytes(bytes);
+    }
+
+    @Override
+    public void destroy() {
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/12ac895f/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
new file mode 100644
index 0000000..dd14cdd
--- /dev/null
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java
@@ -0,0 +1,67 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.crypto.random;
+
+import java.io.*;
+
+/**
+ * use "/dev/urandom", which is on linux, to implement RandomProvider, so it should be used
on linux.
+ */
+public class NativeRandom implements RandomProvider {
+    private InputStream input;
+    private String randFile = "/dev/urandom";
+
+    @Override
+    public void init() {
+        try {
+            input = new FileInputStream(randFile);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void setSeed(byte[] seed) {
+        try {
+            OutputStream output = new FileOutputStream(randFile);
+            output.write(seed);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void nextBytes(byte[] bytes) {
+        try {
+            input.read(bytes);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void destroy() {
+        try {
+            input.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}


Mime
View raw message