After much trouble I have discovered the solution to my troubles:

Unbeknownst to me we had some session keys that required a private key
and some that did not - while we migrated to a world in which all
sessions required private keys.
I was successfully getting results from the session keys which did not
require private key authentication.
Then one result which caused me problems did require private key
authentication.

The solution was to add our private key to the AuthSub authentication.

Then I had to figure out that our private key was generated with
OpenSSL with is not supported by java.  I had to convert our private
key to .pk8 format. and then authenticate.
Here is how to convert the .pem file to a .pk8 file:
     openssl pkcs8 -in google_cert.pem -topk8 -nocrypt -out
google_cert.pk8

Here is code for how I loaded our key.  The key then is the second
parameter to myService.setAuthSubToken(session,key);

<snip>
import org.apache.commons.io.FileUtils;


import com.google.gdata.client.calendar.CalendarQuery;
import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.calendar.CalendarEntry;
import com.google.gdata.data.calendar.CalendarEventEntry;
import com.google.gdata.data.calendar.CalendarEventFeed;
import com.google.gdata.data.calendar.CalendarFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
import
com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
import com.sun.org.apache.xml.internal.security.utils.Base64;

public void loadOurGooglePrivateKey() {
                        File keyFile = null;
                        try {
                                keyFile = new File(ourGooglePrivateKeyFileName);
                        } catch (Exception e) {
                                getLog().error("Unable to open google private 
key file");
                        }

                        String content = null;
                        try {
                                content = FileUtils.readFileToString(keyFile);
                        } catch (IOException e) {
                                getLog().error("Unable to read google private 
key file");
                        }

                        String header = "-----BEGIN PRIVATE KEY-----\n";
                        String footer = "\n-----END PRIVATE KEY-----";
                        int startIndex = content.indexOf(header);
                        if(startIndex == -1){
                                getLog().error("Unable to parge google private 
key file header");
                                content = null;
                        }
                        else{
                                int endIndex = content.indexOf(footer);
                                if(endIndex == -1){
                                        getLog().error("Unable to parge google 
private key file footer");
                                        content = null;
                                }
                                else{
                                        content = 
content.substring(startIndex+header.length(),endIndex);
                                        getLog().debug("Parsed key:\n"+content);
                                }
                        }


                        byte[] decodedBuffer = null;
                        try {
                                decodedBuffer = Base64.decode(content);
                        } catch (Base64DecodingException e) {
                                getLog().error("Unable to decode google private 
key file");
                        }

                        KeyFactory keyFactory = null;
                        try {
                                keyFactory = KeyFactory.getInstance("RSA");
                        } catch (NoSuchAlgorithmException e) {
                                getLog().error("Unable to create an RSA private 
key from google
private key file");
                        }

                        PKCS8EncodedKeySpec privateKeySpec = new 
PKCS8EncodedKeySpec
(decodedBuffer);

                        try {
                                ourGooglePrivateKey = 
keyFactory.generatePrivate(privateKeySpec);
                        } catch (InvalidKeySpecException e) {
                                getLog().log(Level.ERROR,"Unable to generate a 
private key from
google private key spec",e);
                        }
                        getLog().info("Done loading Google Private Key");
                }
        }
</snip>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to