Exemplo n.º 1
0
func (s *signer) Sign(purpose, message []byte) (security.Signature, error) {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	signatureSign := jutil.ClassSign("io.v.v23.security.VSignature")
	jSig, err := jutil.CallObjectMethod(env, s.jSigner, "sign", []jutil.Sign{jutil.ArraySign(jutil.ByteSign), jutil.ArraySign(jutil.ByteSign)}, signatureSign, purpose, message)
	if err != nil {
		return security.Signature{}, err
	}
	return GoSignature(env, jSig)
}
Exemplo n.º 2
0
//export Java_io_v_android_v23_V_nativeInitGlobalAndroid
func Java_io_v_android_v23_V_nativeInitGlobalAndroid(jenv *C.JNIEnv, _ C.jclass, jOptions C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	jOpts := jutil.Object(uintptr(unsafe.Pointer(jOptions)))

	// Don't allow broken stderr/out to kill our program due to
	// sigpipe.  Note that we just ignore all these signals.
	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGPIPE)

	if err := Init(env); err != nil {
		jutil.JThrowV(env, err)
		return
	}

	// Setup logging.
	_, _, level, vmodule, err := loggingOpts(env, jOpts)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	// Disable any logging to STDERR.
	// This assumes that vlog.Log is the underlying logging system for.
	vlog.Log.Configure(vlog.OverridePriorConfiguration(true), vlog.LogToStderr(false), vlog.AlsoLogToStderr(false), level, vmodule)

	// Setup discovery plugins.
	if err := jdplugins.Init(env); err != nil {
		jutil.JThrowV(env, err)
		return
	}

	// Setup namespace.
	android.SetNamespaceFactory(func(ctx *context.T, ns namespace.T, _ ...string) (namespace.T, error) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		jContext, err := jcontext.JavaContext(env, ctx, nil)
		if err != nil {
			return nil, err
		}
		contextSign := jutil.ClassSign("io.v.v23.context.VContext")
		wakeupMountRoot, err := jutil.CallStaticStringMethod(env, jVClass, "getWakeupMountRoot", []jutil.Sign{contextSign}, jContext)
		if err != nil {
			return nil, err
		}
		if wakeupMountRoot == "" {
			return ns, nil
		}
		if !naming.Rooted(wakeupMountRoot) {
			return nil, fmt.Errorf("wakeup mount root %s must be ... rooted.", wakeupMountRoot)
		}
		return &wakeupNamespace{
			wakeupMountRoot: wakeupMountRoot,
			ns:              ns,
		}, nil
	})
}
Exemplo n.º 3
0
func (chooser *jniAddressChooser) ChooseAddresses(protocol string, candidates []net.Addr) ([]net.Addr, error) {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	jCandidates, err := JavaNetworkAddressArray(env, candidates)
	if err != nil {
		return nil, err
	}
	addrsSign := jutil.ArraySign(jutil.ClassSign("io.v.v23.rpc.NetworkAddress"))
	jAddrs, err := jutil.CallObjectMethod(env, chooser.jChooser, "choose", []jutil.Sign{jutil.StringSign, addrsSign}, addrsSign, protocol, jCandidates)
	if err != nil {
		return nil, err
	}
	return GoNetworkAddressArray(env, jAddrs)
}
Exemplo n.º 4
0
func (c *callImpl) Context() *context.T {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	contextSign := jutil.ClassSign("io.v.v23.context.VContext")
	jCtx, err := jutil.CallObjectMethod(env, c.jCall, "context", nil, contextSign)
	if err != nil {
		log.Printf("Couldn't get Java Vanadium context: %v", err)
	}
	ctx, _, err := jcontext.GoContext(env, jCtx)
	if err != nil {
		log.Printf("Couldn't convert Java Vanadium context to Go: %v", err)
	}
	return ctx
}
Exemplo n.º 5
0
// GoListenSpec converts the provided Go ListenSpec into a Java ListenSpec.
func JavaListenSpec(env jutil.Env, spec rpc.ListenSpec) (jutil.Object, error) {
	jAddrs, err := JavaListenAddrArray(env, spec.Addrs)
	if err != nil {
		return jutil.NullObject, err
	}
	jChooser, err := JavaAddressChooser(env, spec.AddressChooser)
	if err != nil {
		return jutil.NullObject, err
	}
	addressSign := jutil.ClassSign("io.v.v23.rpc.ListenSpec$Address")
	jSpec, err := jutil.NewObject(env, jListenSpecClass, []jutil.Sign{jutil.ArraySign(addressSign), jutil.StringSign, addressChooserSign}, jAddrs, spec.Proxy, jChooser)
	if err != nil {
		return jutil.NullObject, err
	}
	return jSpec, nil
}
Exemplo n.º 6
0
func (j javaGlobber) Glob__(ctx *context.T, call rpc.GlobServerCall, g *glob.Glob) error {
	// TODO(sjr,rthellend): Update the Java API to match the new GO API.
	env, freeFunc := jutil.GetEnv()
	jContext, err := jcontext.JavaContext(env, ctx, nil)
	if err != nil {
		freeFunc()
		return err
	}
	jServerCall, err := JavaServerCall(env, call)
	if err != nil {
		freeFunc()
		return err
	}
	convert := func(input jutil.Object) (interface{}, error) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		var reply naming.GlobReply
		if err := jutil.GoVomCopy(env, input, jGlobReplyClass, &reply); err != nil {
			return nil, err
		}
		return reply, nil
	}
	send := func(item interface{}) error {
		reply, ok := item.(naming.GlobReply)
		if !ok {
			return fmt.Errorf("Expected item of type naming.GlobReply, got: %T", reply)
		}
		return call.SendStream().Send(reply)
	}
	close := func() error {
		return nil
	}
	jOutputChannel, err := jchannel.JavaOutputChannel(env, ctx, nil, convert, send, close)
	if err != nil {
		freeFunc()
		return err
	}
	channelSign := jutil.ClassSign("io.v.v23.OutputChannel")
	// This method will invoke the freeFunc().
	_, err = jutil.CallStaticFutureMethod(env, freeFunc, jServerRPCHelperClass, "glob", []jutil.Sign{invokerSign, contextSign, serverCallSign, jutil.StringSign, channelSign}, j.i.jInvoker, jContext, jServerCall, g.String(), jOutputChannel)
	return err
}
Exemplo n.º 7
0
// javaStreamServerCall converts the provided Go serverCall into a Java StreamServerCall
// object.
func javaStreamServerCall(env jutil.Env, jContext jutil.Object, call rpc.StreamServerCall) (jutil.Object, error) {
	if call == nil {
		return jutil.NullObject, fmt.Errorf("Go StreamServerCall value cannot be nil")
	}
	jStream, err := javaStream(env, jContext, call)
	if err != nil {
		return jutil.NullObject, err
	}
	jServerCall, err := JavaServerCall(env, call)
	if err != nil {
		return jutil.NullObject, err
	}
	serverCallSign := jutil.ClassSign("io.v.v23.rpc.ServerCall")
	ref := jutil.GoNewRef(&call) // Un-refed when the Java StreamServerCall object is finalized.
	jStreamServerCall, err := jutil.NewObject(env, jStreamServerCallImplClass, []jutil.Sign{jutil.LongSign, streamSign, serverCallSign}, int64(ref), jStream, jServerCall)
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jStreamServerCall, nil
}
Exemplo n.º 8
0
func (s *signer) PublicKey() security.PublicKey {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	publicKeySign := jutil.ClassSign("java.security.interfaces.ECPublicKey")
	jPublicKey, err := jutil.CallObjectMethod(env, s.jSigner, "publicKey", nil, publicKeySign)
	if err != nil {
		log.Printf("Couldn't get Java public key: %v", err)
		return nil
	}
	// Get the encoded version of the public key.
	encoded, err := jutil.CallByteArrayMethod(env, jPublicKey, "getEncoded", nil)
	if err != nil {
		log.Printf("Couldn't get encoded data for Java public key: %v", err)
		return nil
	}
	key, err := security.UnmarshalPublicKey(encoded)
	if err != nil {
		log.Printf("Couldn't parse Java ECDSA public key: " + err.Error())
		return nil
	}
	return key
}
Exemplo n.º 9
0
	"v.io/x/ref/lib/dispatcher"
	"v.io/x/ref/services/syncbase/discovery"
	"v.io/x/ref/services/syncbase/server"
	"v.io/x/ref/services/syncbase/vsync"

	jrpc "v.io/x/jni/impl/google/rpc"
	jutil "v.io/x/jni/util"
	jcontext "v.io/x/jni/v23/context"
	jaccess "v.io/x/jni/v23/security/access"
)

// #include "jni.h"
import "C"

var (
	permissionsSign   = jutil.ClassSign("io.v.v23.security.access.Permissions")
	contextSign       = jutil.ClassSign("io.v.v23.context.VContext")
	storageEngineSign = jutil.ClassSign("io.v.impl.google.services.syncbase.SyncbaseServer$StorageEngine")
	serverSign        = jutil.ClassSign("io.v.v23.rpc.Server")
	idSign            = jutil.ClassSign("io.v.v23.services.syncbase.Id")
	inviteSign        = jutil.ClassSign("io.v.v23.syncbase.Invite")

	jVRuntimeImplClass jutil.Class
	jInviteClass       jutil.Class
)

// Init initializes the JNI code with the given Java environment.  This method
// must be invoked before any other method in this package and must be called
// from the main Java thread (e.g., On_Load()).
func Init(env jutil.Env) error {
	var err error
Exemplo n.º 10
0
	"v.io/v23/naming"
	"v.io/v23/options"
	"v.io/v23/rpc"
	"v.io/v23/security"

	jnamespace "v.io/x/jni/impl/google/namespace"
	jutil "v.io/x/jni/util"
	jsecurity "v.io/x/jni/v23/security"
)

// #include "jni.h"
import "C"

var (
	authorizerSign = jutil.ClassSign("io.v.v23.security.Authorizer")
	mountEntrySign = jutil.ClassSign("io.v.v23.naming.MountEntry")
)

func getAuthorizer(env jutil.Env, obj jutil.Object, field string) (security.Authorizer, error) {
	jAuthorizer, err := jutil.JObjectField(env, obj, field, authorizerSign)
	if err != nil {
		return nil, err
	}

	if !jAuthorizer.IsNull() {
		auth, err := jsecurity.GoAuthorizer(env, jAuthorizer)
		if err != nil {
			return nil, err
		}
		return auth, nil
Exemplo n.º 11
0
// +build java android

package channel

import (
	"unsafe"

	jutil "v.io/x/jni/util"
)

// #include "jni.h"
import "C"

var (
	contextSign = jutil.ClassSign("io.v.v23.context.VContext")
	// Global reference for io.v.impl.google.channel.InputChannelImpl class.
	jInputChannelImplClass jutil.Class
	// Global reference for io.v.impl.google.channel.OutputChannelImpl class.
	jOutputChannelImplClass jutil.Class
)

// Init initializes the JNI code with the given Java environment.  This method
// must be invoked before any other method in this package and must be called
// from the main Java thread (e.g., On_Load()).
func Init(env jutil.Env) error {
	var err error
	jInputChannelImplClass, err = jutil.JFindClass(env, "io/v/impl/google/channel/InputChannelImpl")
	if err != nil {
		return err
	}
Exemplo n.º 12
0
	jutil "v.io/x/jni/util"
	jcontext "v.io/x/jni/v23/context"
	"v.io/x/ref/runtime/protocols/lib/framer"
)

const (
	bluetoothWithPortClassName = "BluetoothWithPort"
	bluetoothWithSdpClassName  = "BluetoothWithSdp"

	// TODO(jhahn,suharshs): Which one is more reliable?
	btClassName = bluetoothWithSdpClassName
)

var (
	contextSign  = jutil.ClassSign("io.v.v23.context.VContext")
	streamSign   = jutil.ClassSign("io.v.android.impl.google.rpc.protocols.bt." + btClassName + "$Stream")
	listenerSign = jutil.ClassSign("io.v.android.impl.google.rpc.protocols.bt." + btClassName + "$Listener")

	// Global reference for io.v.impl.google.rpc.protocols.bt.Bluetooth class.
	jBluetoothClass jutil.Class
)

// Init initializes the JNI code with the given Java environment. This method
// must be called from the main Java thread.
func Init(env jutil.Env) error {
	// Cache global references to all Java classes used by the package.  This is
	// necessary because JNI gets access to the class loader only in the system
	// thread, so we aren't able to invoke FindClass in other threads.
	var err error
	jBluetoothClass, err = jutil.JFindClass(env, "io/v/android/impl/google/rpc/protocols/bt/"+btClassName)
Exemplo n.º 13
0
package context

import (
	"errors"
	"unsafe"

	"v.io/v23/context"
	jutil "v.io/x/jni/util"
)

// #include "jni.h"
// #include <stdlib.h>
import "C"

var (
	classSign      = jutil.ClassSign("java.lang.Class")
	doneReasonSign = jutil.ClassSign("io.v.v23.context.VContext$DoneReason")
	// Global reference for io.v.v23.context.VContext class.
	jVContextClass jutil.Class
	// Global reference for io.v.v23.context.VContext$DoneReason
	jDoneReasonClass jutil.Class
)

// Init initializes the JNI code with the given Java environment. This method
// must be called from the main Java thread.
func Init(env jutil.Env) error {
	// Cache global references to all Java classes used by the package.  This is
	// necessary because JNI gets access to the class loader only in the system
	// thread, so we aren't able to invoke FindClass in other threads.
	var err error
	jVContextClass, err = jutil.JFindClass(env, "io/v/v23/context/VContext")
Exemplo n.º 14
0
	"v.io/v23"
	"v.io/v23/security/access"
	"v.io/x/ref/services/mounttable/mounttablelib"

	"v.io/v23/options"
	jrpc "v.io/x/jni/impl/google/rpc"
	jutil "v.io/x/jni/util"
	jcontext "v.io/x/jni/v23/context"
	jaccess "v.io/x/jni/v23/security/access"
)

// #include "jni.h"
import "C"

var (
	permissionsSign = jutil.ClassSign("io.v.v23.security.access.Permissions")
	contextSign     = jutil.ClassSign("io.v.v23.context.VContext")
	serverSign      = jutil.ClassSign("io.v.v23.rpc.Server")

	jVRuntimeImplClass jutil.Class
)

// Init initializes the JNI code with the given Java environment.  This method
// must be invoked before any other method in this package and must be called
// from the main Java thread (e.g., On_Load()).
func Init(env jutil.Env) error {
	var err error
	jVRuntimeImplClass, err = jutil.JFindClass(env, "io/v/impl/google/rt/VRuntimeImpl")
	if err != nil {
		return err
	}
Exemplo n.º 15
0
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build java android

package naming

import (
	jutil "v.io/x/jni/util"
)

// #include "jni.h"
import "C"

var (
	endpointSign = jutil.ClassSign("io.v.v23.naming.Endpoint")

	// Global reference for io.v.impl.google.naming.EndpointImpl.
	jEndpointImplClass jutil.Class
)

func Init(env jutil.Env) error {
	// Cache global references to all Java classes used by the package.  This is
	// necessary because JNI gets access to the class loader only in the system
	// thread, so we aren't able to invoke FindClass in other threads.
	var err error
	jEndpointImplClass, err = jutil.JFindClass(env, "io/v/impl/google/naming/EndpointImpl")
	if err != nil {
		return err
	}
	return nil
Exemplo n.º 16
0
// JavaServerStatus converts the provided rpc.ServerStatus value into a Java
// ServerStatus object.
func JavaServerStatus(env jutil.Env, status rpc.ServerStatus) (jutil.Object, error) {
	// Create Java state enum value.
	jState, err := JavaServerState(env, status.State)
	if err != nil {
		return jutil.NullObject, err
	}

	// Create Java array of publisher entries.
	pubarr := make([]jutil.Object, len(status.PublisherStatus))
	for i, e := range status.PublisherStatus {
		var err error
		if pubarr[i], err = JavaPublisherEntry(env, e); err != nil {
			return jutil.NullObject, err
		}
	}
	jPublisherStatus, err := jutil.JObjectArray(env, pubarr, jPublisherEntryClass)
	if err != nil {
		return jutil.NullObject, err
	}

	// Create an array of endpoint strings.
	eps := make([]string, len(status.Endpoints))
	for i, ep := range status.Endpoints {
		eps[i] = ep.String()
	}

	lnErrors := make(map[jutil.Object]jutil.Object)
	for addr, lerr := range status.ListenErrors {
		jAddr, err := JavaListenAddr(env, addr.Protocol, addr.Address)
		if err != nil {
			return jutil.NullObject, err
		}
		jVExp, err := jutil.JVException(env, lerr)
		if err != nil {
			return jutil.NullObject, err
		}
		lnErrors[jAddr] = jVExp
	}
	jLnErrors, err := jutil.JObjectMap(env, lnErrors)
	if err != nil {
		return jutil.NullObject, err
	}

	proxyErrors := make(map[jutil.Object]jutil.Object)
	for s, perr := range status.ProxyErrors {
		jVExp, err := jutil.JVException(env, perr)
		if err != nil {
			return jutil.NullObject, err
		}
		proxyErrors[jutil.JString(env, s)] = jVExp
	}
	jProxyErrors, err := jutil.JObjectMap(env, proxyErrors)
	if err != nil {
		return jutil.NullObject, err
	}

	// Create final server status.
	publisherEntrySign := jutil.ClassSign("io.v.v23.rpc.PublisherEntry")
	jServerStatus, err := jutil.NewObject(env, jServerStatusClass, []jutil.Sign{serverStateSign, jutil.BoolSign, jutil.ArraySign(publisherEntrySign), jutil.ArraySign(jutil.StringSign), jutil.MapSign, jutil.MapSign}, jState, status.ServesMountTable, jPublisherStatus, eps, jLnErrors, jProxyErrors)
	if err != nil {
		return jutil.NullObject, err
	}
	return jServerStatus, nil
}
Exemplo n.º 17
0
	"v.io/x/lib/vlog"

	jble "v.io/x/jni/impl/google/rpc/protocols/ble"
	jbt "v.io/x/jni/impl/google/rpc/protocols/bt"
	jutil "v.io/x/jni/util"
	jcontext "v.io/x/jni/v23/context"
	jnaming "v.io/x/jni/v23/naming"
	jopts "v.io/x/jni/v23/options"
	jsecurity "v.io/x/jni/v23/security"
)

// #include "jni.h"
import "C"

var (
	contextSign          = jutil.ClassSign("io.v.v23.context.VContext")
	dispatcherSign       = jutil.ClassSign("io.v.v23.rpc.Dispatcher")
	invokerSign          = jutil.ClassSign("io.v.v23.rpc.Invoker")
	serverCallSign       = jutil.ClassSign("io.v.v23.rpc.ServerCall")
	streamServerCallSign = jutil.ClassSign("io.v.v23.rpc.StreamServerCall")
	listenAddrSign       = jutil.ClassSign("io.v.v23.rpc.ListenSpec$Address")
	addressChooserSign   = jutil.ClassSign("io.v.v23.rpc.AddressChooser")
	serverStateSign      = jutil.ClassSign("io.v.v23.rpc.ServerState")
	streamSign           = jutil.ClassSign("io.v.v23.rpc.Stream")

	// Global reference for io.v.impl.google.rpc.AddressChooserImpl class.
	jAddressChooserImplClass jutil.Class
	// Global reference for io.v.impl.google.rpc.ServerImpl class.
	jServerImplClass jutil.Class
	// Global reference for io.v.impl.google.rpc.ClientImpl class.
	jClientImplClass jutil.Class
Exemplo n.º 18
0
	"path/filepath"
	"unsafe"

	"v.io/v23"
	"v.io/x/ref/services/groups/lib"

	jrpc "v.io/x/jni/impl/google/rpc"
	jutil "v.io/x/jni/util"
	jcontext "v.io/x/jni/v23/context"
)

// #include "jni.h"
import "C"

var (
	contextSign       = jutil.ClassSign("io.v.v23.context.VContext")
	storageEngineSign = jutil.ClassSign("io.v.impl.google.services.groups.GroupServer$StorageEngine")
	serverSign        = jutil.ClassSign("io.v.v23.rpc.Server")

	jVRuntimeImplClass jutil.Class
)

// Init initializes the JNI code with the given Java environment.  This method
// must be invoked before any other method in this package and must be called
// from the main Java thread (e.g., On_Load()).
func Init(env jutil.Env) error {
	var err error
	jVRuntimeImplClass, err = jutil.JFindClass(env, "io/v/impl/google/rt/VRuntimeImpl")
	if err != nil {
		return err
	}
Exemplo n.º 19
0
	"v.io/v23/verror"

	idiscovery "v.io/x/ref/lib/discovery"
	gdiscovery "v.io/x/ref/lib/discovery/global"

	jchannel "v.io/x/jni/impl/google/channel"
	jutil "v.io/x/jni/util"
	jcontext "v.io/x/jni/v23/context"
)

// #include "jni.h"
// #include <stdlib.h>
import "C"

var (
	adIdSign          = jutil.ClassSign("io.v.v23.discovery.AdId")
	advertisementSign = jutil.ClassSign("io.v.v23.discovery.Advertisement")

	jAdIdClass            jutil.Class // io.v.v23.discovery.AdId
	jAdvertisementClass   jutil.Class // io.v.v23.discovery.Advertisement
	jBlessingPatternClass jutil.Class // io.v.v23.security.BlessingPattern
	jDiscoveryImplClass   jutil.Class // io.v.impl.google.lib.discovery.DiscoveryImpl
	jUpdateImplClass      jutil.Class // io.v.impl.google.lib.discovery.UpdateImpl
	jUUIDClass            jutil.Class // java.util.UUID
)

// Init initializes the JNI code with the given Java environment. This method
// must be called from the main Java thread.
func Init(env jutil.Env) error {
	// Cache global references to all Java classes used by the package.  This is
	// necessary because JNI gets access to the class loader only in the system
Exemplo n.º 20
0
import (
	"fmt"
	"unsafe"

	"v.io/v23/security"
	jutil "v.io/x/jni/util"
	jcontext "v.io/x/jni/v23/context"
	vsecurity "v.io/x/ref/lib/security"
)

// #include "jni.h"
import "C"

var (
	contextSign          = jutil.ClassSign("io.v.v23.context.VContext")
	dischargeSign        = jutil.ClassSign("io.v.v23.security.Discharge")
	dischargeImpetusSign = jutil.ClassSign("io.v.v23.security.DischargeImpetus")
	principalSign        = jutil.ClassSign("io.v.v23.security.VPrincipal")
	blessingsSign        = jutil.ClassSign("io.v.v23.security.Blessings")
	wireBlessingsSign    = jutil.ClassSign("io.v.v23.security.WireBlessings")
	wireDischargeSign    = jutil.ClassSign("io.v.v23.security.WireDischarge")
	blessingStoreSign    = jutil.ClassSign("io.v.v23.security.BlessingStore")
	blessingRootsSign    = jutil.ClassSign("io.v.v23.security.BlessingRoots")
	blessingPatternSign  = jutil.ClassSign("io.v.v23.security.BlessingPattern")
	signerSign           = jutil.ClassSign("io.v.v23.security.VSigner")
	caveatSign           = jutil.ClassSign("io.v.v23.security.Caveat")
	callSign             = jutil.ClassSign("io.v.v23.security.Call")
	signatureSign        = jutil.ClassSign("io.v.v23.security.VSignature")
	idSign               = jutil.ClassSign("io.v.v23.uniqueid.Id")
	publicKeySign        = jutil.ClassSign("java.security.interfaces.ECPublicKey")