* Licensed 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.
public final String x500;
public final String x509;
public ByteBuffer serial;
-
+
public X509(String ca, String id, String x500, String x509, ByteBuffer serial) {
- this.ca = ca;
- this.id = id;
- this.x500 = x500;
- this.x509 = x509;
- this.serial = serial;
+ this.ca = ca;
+ this.id = id;
+ this.x500 = x500;
+ this.x509 = x509;
+ this.serial = serial;
}
-
+
public static void load(Trans trans, Session session, Visitor<X509> visitor) {
- load(trans,session,"select ca, id, x500, x509, serial from authz.x509;", visitor);
+ load(trans,session, "" , visitor);
}
- private static void load(Trans trans, Session session, String query, Visitor<X509> visitor) {
+ public static void load(Trans trans, Session session, String where, Visitor<X509> visitor) {
+ load(trans,session, visitor,"select ca, id, x500, x509, serial from authz.x509 " + where +';');
+ }
+
+
+ private static void load(Trans trans, Session session, Visitor<X509> visitor, String query) {
trans.info().log( "query: " + query );
TimeTaken tt = trans.start("Read X509", Env.REMOTE);
-
+
ResultSet results;
try {
Statement stmt = new SimpleStatement( query );
tt = trans.start("Load X509s", Env.SUB);
try {
while (iter.hasNext()) {
- ++count;
+ ++count;
row = iter.next();
visitor.visit(new X509(row.getString(0),row.getString(1), row.getString(2),row.getString(3),row.getBytes(4)));
}
trans.info().log("Found",count,"X509 Certificates");
}
}
-
+
public static long count(Trans trans, Session session) {
String query = "select count(*) from authz.x509 LIMIT 1000000;";
trans.info().log( "query: " + query );
tt.done();
}
}
-
-
- public void row(CSV.Writer cw, X509Certificate x509Cert) {
- cw.row("x509",ca,Hash.toHex(serial.array()),Chrono.dateOnlyStamp(x509Cert.getNotAfter()),x500);
- }
-
-
- public static void row(StringBuilder sb, List<String> row) {
- sb.append("DELETE from authz.x509 WHERE ca='");
- sb.append(row.get(1));
- sb.append("' AND serial=");
- sb.append(row.get(2));
- sb.append(";\n");
- }
-
-
- public static String histSubject(List<String> row) {
- return row.get(4);
- }
-
-
- public static String histMemo(String fmt, List<String> row) {
- String id="n/a";
- for(String s : Split.splitTrim(',', row.get(4))) {
- if(s.startsWith("OU=") && s.indexOf('@')>=0) {
- int colon = s.indexOf(':');
- if(colon<0) {
- colon=s.length();
- }
- id=s.substring(3,colon);
- break;
- }
- }
- return String.format(fmt, "Cert for " + id,"CA " + row.get(1),row.get(3));
- }
+
+
+ public void row(CSV.Writer cw, X509Certificate x509Cert) {
+ cw.row("x509",ca,Hash.toHex(serial.array()),Chrono.dateOnlyStamp(x509Cert.getNotAfter()),x500);
+ }
+
+ public void row(CSV.Writer cw, X509Certificate x509Cert,String reason) {
+ cw.row("x509",ca,Hash.toHex(serial.array()),Chrono.dateOnlyStamp(x509Cert.getNotAfter()),x500,reason);
+ }
+
+
+ public static void row(StringBuilder sb, List<String> row) {
+ sb.append("DELETE from authz.x509 WHERE ca='");
+ sb.append(row.get(1));
+ sb.append("' AND serial=");
+ sb.append(row.get(2));
+ sb.append(";\n");
+ }
+
+ public static void batchDelete(StringBuilder sb, List<String> row) {
+ sb.append("DELETE from authz.x509 WHERE ca='");
+ sb.append(row.get(1));
+ sb.append("' AND serial=");
+ sb.append(row.get(2));
+ sb.append(";\n");
+ }
+ public static String histSubject(List<String> row) {
+ return row.get(4);
+ }
+
+
+ public static String histMemo(String fmt, List<String> row) {
+ String id="n/a";
+ for(String s : Split.splitTrim(',', row.get(4))) {
+ if(s.startsWith("OU=") && s.indexOf('@')>=0) {
+ int colon = s.indexOf(':');
+ if(colon<0) {
+ colon=s.length();
+ }
+ id=s.substring(3,colon);
+ break;
+ }
+ }
+ return String.format(fmt, "Cert for " + id,"CA " + row.get(1),row.get(3));
+ }
}
\ No newline at end of file